You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have two cells, one containing two imports, and another containing a function definition.
When I run cargo run -p ruff_cli -- check Untitled.ipynb -n --watch --show-source, I get:
Untitled.ipynb:cell 1:2:8: F401 [*] `sys` imported but unused
|
1 | import os
2 | import sys
| ^^^ F401
3 | def f(x):
4 | y = x * x
|
= help: Remove unused import: `sys`
Untitled.ipynb:cell 2:2:5: F841 [*] Local variable `y` is assigned to but never used
|
2 | import sys
3 | def f(x):
4 | y = x * x
| ^ F841
5 | print(x * x)
6 | f(2)
|
= help: Remove assignment to unused variable `y`
I think the code frames need to be reindexed. Notice that in the second error, the location is reported as cell 2:2:5, but in the code frame, the violation is on line 4.
Similarly, we should omit any contents from adjoining cells when displaying the code frame (in my opinion) -- so the second diagnostic shouldn't show the import sys.
The text was updated successfully, but these errors were encountered:
Ah yes, this is true. I'll need to look into how source is being shown currently. Most likely the cell separation concept could be common for --show-source and --diff option.
## Summary
Consider Jupyter index for code frames (`--show-source`).
This solves two problems as mentioned in the linked issue:
> Omit any contents from adjoining cells
If the Jupyter index is present, we'll use that to check if the
surrounding
lines belong to the same cell as the content line. If not, we'll skip
that line
until we either reach the one which does or we reach the content line.
> code frame line number
If the Jupyter index is present, we'll use that to get the actual start
line in
corresponding to the computed start index.
## Test Plan
`cargo run --bin ruff -- check --no-cache --isolated --select=ALL --show-source /path/to/notebook.ipynb`
fixes: #5395
I have two cells, one containing two imports, and another containing a function definition.
When I run
cargo run -p ruff_cli -- check Untitled.ipynb -n --watch --show-source
, I get:I think the code frames need to be reindexed. Notice that in the second error, the location is reported as
cell 2:2:5
, but in the code frame, the violation is on line 4.Similarly, we should omit any contents from adjoining cells when displaying the code frame (in my opinion) -- so the second diagnostic shouldn't show the
import sys
.The text was updated successfully, but these errors were encountered: