-
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
Fixes on Jupyter notebooks cause panics when fix replaces/deletes multiple cells #14445
Comments
Thanks so much for this! This can be reproduced with a notebook that just consists of three empty cells. We are somehow counting empty cells as newlines and then erroring when we try to "delete" them. |
Actually this bug has a wider blast radius. If you make a notebook with three cells like this: a = [1]
a.append(2)
# new cell
a.append(3)
# new cell
a.append(4) and apply the unsafe fix for |
I'm guessing that cell deletion is creating a problem when |
The root cause is because the edit spans across the cell boundary which is an invariant we like to follow. In the case of Refer to how the cell offsets are being updated (incorrectly): // Original cell offsets
[crates/ruff_notebook/src/notebook.rs:229:9] &self.cell_offsets = CellOffsets(
[
0,
20,
32,
44,
],
)
// The edit
[crates/ruff_linter/src/fix/mod.rs:97:13] edit = Edit {
range: 8..43,
content: Some(
"x.extend((2, 3, 4))",
),
}
// Source map created for the edit
[crates/ruff_notebook/src/notebook.rs:230:9] source_map = SourceMap(
[
SourceMarker {
source: 8,
dest: 8,
},
SourceMarker {
source: 43,
dest: 27,
},
]
)
// After the above source map is applied to update the cell offsets
[crates/ruff_notebook/src/notebook.rs:263:9] &self.cell_offsets = CellOffsets(
[
0,
20,
32,
28,
],
) I don't this rule existed when I implemented this. |
So, I think we need to consider replacement and deletion across cell boundaries. Insertion is fine because it's at an exact position which isn't going to affect this logic. There's some details on how the source markers are being used to update the cell offsets in the PR description: #4665. |
Oh that's neat- and nice drawing! For deletions we could just delete the cell and adjust the cell offsets (so there will be fewer cell offsets than there used to be). What do you think? For replacements it's a little less clear what to do, since folks separate things across cells in order to control what executes when. |
The thing is we don't really know the kind of edit when trying to update the cell offsets. The main reason for adding the I think we'll need a generic solution which just looks at source markers to determine that certain cell offsets needs to be removed. I'm not exactly sure what this looks like. |
command:
ruff check .\src\test.ipynb --fix --diff
(No panic when
--isolated
included)ruff version: 0.7.4
pyproject.toml
The text was updated successfully, but these errors were encountered: