Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W391 reported but not fixed in Jupyter notebook #13763

Open
DimitriPapadopoulos opened this issue Oct 15, 2024 · 2 comments · May be fixed by #15308
Open

W391 reported but not fixed in Jupyter notebook #13763

DimitriPapadopoulos opened this issue Oct 15, 2024 · 2 comments · May be fixed by #15308
Labels
bug Something isn't working notebook Related to (Jupyter) notebooks

Comments

@DimitriPapadopoulos
Copy link
Contributor

DimitriPapadopoulos commented Oct 15, 2024

Ruff emits a W391 error, a spurious one as far as I can see, and --fix doesn't modify the file:

$ ruff check --isolated --no-cache --extend-select W --preview --fix file.ipynb
Found 1 error (1 fixed, 0 remaining).
$ 
$ ruff check --isolated --no-cache --extend-select W --preview --fix file.ipynb
Found 1 error (1 fixed, 0 remaining).
$ 

The issue is associated to this line in the Jupyter Notebook:

   "source": []
  • List of keywords you searched for before creating this issue: "W391"

  • A minimal code snippet that reproduces the bug.

    code snippet
    {
     "cells": [
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [
        {
         "name": "stdout",
         "output_type": "stream",
         "text": [
          "True\n"
         ]
        }
       ],
       "source": [
        "True"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
       "source": []
      }
     ],
     "metadata": {
      "kernelspec": {
       "display_name": "Python 3 (ipykernel)",
       "language": "python",
       "name": "python3"
      }
     },
     "nbformat": 4,
     "nbformat_minor": 2
    }
    
  • The command you invoked (e.g., ruff /path/to/file.py --fix), ideally including the --isolated flag.

     ruff check --isolated --no-cache --extend-select W --preview --fix file.ipynb
    
  • The current Ruff settings (any relevant sections from your pyproject.toml).

  • The current Ruff version (ruff --version).

    ruff 0.6.9
    
@DimitriPapadopoulos DimitriPapadopoulos changed the title W391 not fixed in Jupyter notebook W391 reported but not fixed in Jupyter notebook Oct 15, 2024
@dhruvmanila dhruvmanila added bug Something isn't working notebook Related to (Jupyter) notebooks labels Oct 16, 2024
@dhruvmanila
Copy link
Member

Yeah, I think we should limit this rule to individual cells and not for the concatenated content.

@dhruvmanila
Copy link
Member

dhruvmanila commented Oct 16, 2024

The challenge here is that the rule looks at the tokens, so we'd need to basically run the too_many_newlines_at_end_of_file function for the tokens corresponding to each cell. I think that can be done by using the CellOffsets. We'd need to keep an iterator of cell offsets and loop over all the tokens of the file in reverse order and reset some state to indicate that we're at the end of the cell. This would be similar to what's being done for blank line rules by the LinePreprocessor.

DimitriPapadopoulos added a commit to DimitriPapadopoulos/numcodecs that referenced this issue Oct 20, 2024
DimitriPapadopoulos added a commit to DimitriPapadopoulos/numcodecs that referenced this issue Oct 20, 2024
DimitriPapadopoulos added a commit to DimitriPapadopoulos/numcodecs that referenced this issue Oct 23, 2024
DimitriPapadopoulos added a commit to DimitriPapadopoulos/numcodecs that referenced this issue Oct 31, 2024
DimitriPapadopoulos added a commit to DimitriPapadopoulos/numcodecs that referenced this issue Nov 24, 2024
DimitriPapadopoulos added a commit to DimitriPapadopoulos/numcodecs that referenced this issue Nov 24, 2024
DimitriPapadopoulos added a commit to DimitriPapadopoulos/numcodecs that referenced this issue Nov 29, 2024
DimitriPapadopoulos added a commit to DimitriPapadopoulos/numcodecs that referenced this issue Dec 28, 2024
dstansby pushed a commit to zarr-developers/numcodecs that referenced this issue Dec 28, 2024
* Enforce ruff rule RUF001

Disable the rule directly in the incriminated test file.

* Enforce ruff/pyupgrade rule UP007

UP007 Use `X | Y` for type annotations

* Enforce ruff/flake8-bugbear rules B028 and B904

* Exclude c-blosc from ruff linting

* Ignore ruff/pycodestyle rule W391

astral-sh/ruff#13763

* Enforce ruff/flake8-logging rules (LOG)

* Enforce ruff/flake8-implicit-str-concat rules (ISC)

* Enforce ruff/flake8-executable rules (EXE)

* Enforce ruff/flake8-future-annotations rules (FA)

* Enforce ruff/flake8-return rules (RET)

* Enforce ruff/flake8-slots rules (SLOT)

* Add "numcodecs" to "src"

The directories to consider when resolving first- vs. third-party imports.

* Enforce ruff/flake8-simplify rules (SIM)

* Enforce ruff/flake8-tidy-imports rules (TID)

* Conflicting ruff lint rules

The linter includes some rules that, when enabled, can cause conflicts
with the formatter, leading to unexpected behavior. None None of these
rules are included in Ruff's default configuration. However, since we
have enabled some relevant rule sets, we disable these rules.

* Enforce ruff/tryceratops rules (TRY)

* Update ruff to 0.8.0

* Ignore ruff/flake8-simplify rule SIM105

SIM105 Use `contextlib.suppress(ImportError)` instead of `try`-`except`-`pass`

* Ignore ruff/tryceratops rule TRY301

TRY301 Abstract `raise` to an inner function

* Apply ruff/flake8-bugbear rule B904

B904 Within an `except` clause, raise exceptions with `raise ... from err`
     or `raise ... from None` to distinguish them from errors in exception
     handling

* Apply ruff/flake8-bugbear rule B028

B028 No explicit `stacklevel` keyword argument found

* Apply ruff rule RUF022

RUF022 `__all__` is not sorted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working notebook Related to (Jupyter) notebooks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants