-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
E302 and E305 cause the linter and formatter to make conflicting changes in notebooks #10228
Comments
Thanks for the excellent write up. Agree, that is a bug in |
I can try to fix it if no one has started working on it yet. |
This comment was marked as outdated.
This comment was marked as outdated.
@MichaReiser You are only talking about the comment above, right ? |
@hoel-bagard Yes, my comment was specific about compatibility within typing stub file (pyi). The incompatibility documented in this issue isn't solved. @dhruvmanila any recommendation how to fix this or is this something you could take on? |
We do have custom handling for rules in Notebooks ( There's a helper function which checks if it's the last expression in the cell. We could either use the same function or provide a similar function depending on what the needs are here and check if we're at the cell boundary. If so, ignore checking for blank lines. In the linked function, the tokenizer would start at the end of the expression. But for I'm not sure how exactly to get the range of the entire function / class as these rules are token-based and not AST-based. For an AST node we can directly get the end of the function / class node. It might be that I would need to look into it in detail to understand that. @MichaReiser I'm not sure if I want to look into it right now unless it's a priority. |
Thanks @dhruvmanila. @hoel-bagard would you be interested to look into this issue? I'm sure @dhruvmanila would reply to any questions you have |
@MichaReiser I would be interested to look into it yes. I'll start by looking at the references given by @dhruvmanila, and ask if I get stuck on something. |
…cell (#10291) ## Summary Closes #10228 The PR makes the blank lines rules keep track of the cell status when running on a notebook, and makes the rules not trigger when the line is the first of the cell. ## Test Plan The example given in #10228 is added as a fixture, along with a few tests from the main blank lines fixtures.
The new rules introduced in ruff v0.2.2 via #9266 are causing the ruff linter to make conflicting changes in notebook cells that the formatter is then trying to fix.
Here is an example notebook which reproduces the bug:
ruff config:
If you run the commands in this succession and look at the diffs you will notice that the linter adds two lines at the end of:
some_computation
). This is ruleE302
in actionE305
in action.The commands I ran:
ruff check --force-exclude --preview --fix test.ipynb
ruff format --force-exclude --preview test.ipynb
(The
--force-exclude
is because I discovered this bug through pre-commit and I was trying to mimic the pre-commit behaviour)This behaviour happens from v0.2.2 upwards (I've also tested v0.3.0) as long as the preview flag is on.
Let me know if the MRE needs more explanation.
The text was updated successfully, but these errors were encountered: