-
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
jupyter: ruff v0.1.4 ignores variables with the same name as magic commands #8526
Comments
In this case, it's because If you use any other variable name, it will work as expected, but we'll consider how to make this more targeted. |
\cc @dhruvmanila since we discussed this a bit at the time |
Yeah, this is tricky. We could implement the simple solution that we discussed earlier about having support for only The far fetched solution would be to not ignore such cells and perform some semantic analysis on the parsed code but then it could potentially raise a syntax error ( I'd actually want to spend some time figuring out how IPython does it as it could lead to some insights. |
So, IPython is doing exactly that: https://github.com/ipython/ipython/blob/de97f0032dd96e0109780396e9219e8d73073e29/IPython/core/prefilter.py#L428-L467 For something like |
Hmm yeah. We could apply some similar heuristics though they'd need to be more expansive... We could also try parsing, then fallback to automagic if the code doesn't parse, but that will also be wrong in some cases. I'd just really like to avoid doing semantic analysis on the code block to understand how to parse it. |
This is fixed by #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`
This is the previous Jupyter Notebook file, and it had no lint errors with ruff v0.1.3.
When ruff was upgraded to v0.1.4 (deepmodeling/dpdata#573),
import dpdata
got removed,Besides, F821 was complained:
It's obvious that ruff doesn't consider variables in the other cells.
The text was updated successfully, but these errors were encountered: