astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
32.88k stars 1.1k forks source link

Fixes on Jupyter notebooks cause panics when fix replaces/deletes multiple cells #14445

Open beskep opened 4 hours ago

beskep commented 4 hours ago

[tool.ruff] preview = true

[tool.ruff.lint] select = ["W"]



- ipynb file: [test.ipynb.zip](https://github.com/user-attachments/files/17807695/test.ipynb.zip)
dylwil3 commented 3 hours ago

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.

dylwil3 commented 3 hours ago

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 FURB118 you also get a panic.

dhruvmanila commented 2 hours ago

I'm guessing that cell deletion is creating a problem when update_cell_offsets and update_cell_contents are being called.