-
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
False positive F401 due to %%ipytest
line in notebook
#13718
Comments
I don't fully understnad yet what's happening but the code works as expected when I change |
@dhruvmanila do you have an idea why using the |
Yeah, the double percent like ruff/crates/ruff_notebook/src/cell.rs Lines 217 to 244 in fd5fcc4
While, the single percent like |
Oh that's good to know. Thanks. So the solution here would be to move the |
I think it is in its own cell. It's just that the entire cell is currently ignored by Ruff because |
What I mean is that a possible workaround is to change the notebook to have three cells: import ipytest
import pytest
ipytest.autoconfig() %%ipytest def test_simple():
with pytest.raises(TypeError):
print(1 + "a") |
I think then the magic command won't work because it won't be applied to the cell it was previously targeting. |
I just tested it, it's safe to include ruff/crates/ruff_notebook/src/cell.rs Lines 241 to 244 in fd5fcc4
|
## Summary fixes: #13718 ## Test Plan Using the notebook as mentioned in #13718 (comment), this PR does not give the "F821 Undefined name `test_sorted`" diagnostic.
Thank you all for the comments and the fix. My apologies for commenting late. Indeed, the |
Keywords to find existing issue: F401 and ipytest. The following is very similar, but still different, it seems: #10454
A minimal working example would be a Jupyter notebook with the following two cells:
Ruff will report
F401 (unused-import)
for the lineimport pytest
.To reproduce the issue, create a notebook with the above cells, called
bug.ipynb
and run the command:I've tested with with ruff 0.6.3 and 0.6.9. I have the following in my pyproject.toml, but I don't think these settings matter:
As a workaround, one can (obviously) add a comment
# noqa: F401
to the import lineWhen removing the line
%%ipytest
, the problem goes away, but it that doesn't help because the line is doing something useful.Given the easy workaround, this is probably not urgent.
By the way, thanks for creating Ruff!
The text was updated successfully, but these errors were encountered: