-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
F821 false positive in notebook when using magic command as variables #9648
Comments
Yeah we can probably improve our heuristics here to specifically detect assignments. The automagics are actually really complicated because it means that (in general) cells may or may not be unsafe depending on the order of their execution (which we can't know). For example: #8398 (comment). |
I'll try to fix this specific case today :) |
But I need to audit the list of automagics which I dread 😂 |
Fixed in #9653. |
## Summary Given a statement like `colors = 6`, we currently treat the cell as an automagic (since `colors` is an automagic) -- i.e., we assume it's equivalent to `%colors = 6`. This PR adds some additional detection whereby if the statement is an _assignment_, we avoid treating it as such. I audited the list of automagics, and I believe this is safe for all of them. Closes #8526. Closes #9648. ## Test Plan `cargo test`
Thanks! |
Of course! If you see more of these, let us know, since we have to rely on some heuristics for this given the flexibility of notebooks. |
ruff gives false positives for F821 (Undefined name) in notebooks when using magic command as variables. Ok, this is very specific and potentially related to #9644.
In a jupyter notebook when defining a variable which has the same name as a ipython magic command and using this variable in a following cell and not as the first command triggers F821 (wrongly).
Only classify magic commands as magic if they are preceded with a
%
?command
version
MVCE
(I am not sure how to create a MVCE for a jupyter notebook, but I guess it's easy enough...)
The text was updated successfully, but these errors were encountered: