Skip to content
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

Invalid syntax error location for Notebook with ruff format #11453

Open
david-waterworth opened this issue May 16, 2024 · 6 comments · May be fixed by #11456
Open

Invalid syntax error location for Notebook with ruff format #11453

david-waterworth opened this issue May 16, 2024 · 6 comments · May be fixed by #11456
Assignees
Labels
bug Something isn't working notebook Related to (Jupyter) notebooks

Comments

@david-waterworth
Copy link

I'm getting the error error: Failed to parse notebooks/tickets v2.ipynb:1:1:5: Invalid decimal integer literal when I run ruff format . on a project (previously I was using whatever the default vscode formatter is).

I assume the :1:1:5 is a reference to a cell but I cannot parse it, does that mean cell 1, line 1 column 5? And is it 0 or 1 based - either way the message doesn't help as the first cell contains

%load_ext autoreload
%autoreload 2

and the second

from datetime import datetime, timezone
...

Also pre-commit doesn't seem to complain, not does format on save (vscode setting) which I've configured to use Ruff as the default formatter, it's only when I try and format from the cmd line. I tried escaping the space with \ and surrounding the filename with " "

I'm using ruff 0.4.4 (global pipx installation) and my settings are:

[tool.ruff]
extend-include = ["*.ipynb"]

# Same as Black.
line-length = 120
lint.ignore-init-module-imports = true

exclude = []
lint.select = [
    "E",  # pycodestyle errors (settings from FastAPI, thanks, @tiangolo!)
    "W",  # pycodestyle warnings
    "F",  # pyflakes
    "I",  # isort
    "C",  # flake8-comprehensions
    "B",  # flake8-bugbear
]
lint.ignore = [
    "E501",  # line too long, handled by black
    "C901",  # too complex
]
lint.per-file-ignores = { "*.ipynb" = ["E402", "F704", "B018"] }

[tool.ruff.lint.isort]
order-by-type = true
relative-imports-order = "closest-to-furthest"
extra-standard-library = ["typing"]
section-order = ["future", "standard-library", "third-party", "first-party", "local-folder"]
known-first-party = []

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
docstring-code-format = true
docstring-code-line-length = "dynamic"
@charliermarsh
Copy link
Member

Are you able to share the raw notebook file?

@charliermarsh charliermarsh added the needs-info More information is needed from the issue author label May 17, 2024
@david-waterworth
Copy link
Author

I figured it out, right down the bottom there was as cell I missed containing

559/02408930-81c7-47d7-b2b0-ee38cb3f6e62

Which is clearly invalid - it's actually a fragment of a uri I added at some stage to test something and I should have set the cell to markdown or commented it out. The linter was flagging as an error, I guess the only real issue is the message is a bit cryptic, ideally ruff format would report the cell number at least, and maybe that this is a linter error - the image below shows what ruff reports in the "Problems" panel of vscode but ruff format is leaving out some context (also the message below doesn't include the cell number)

image

@dhruvmanila
Copy link
Member

Thanks for the details. So, yeah the ruff format command does not include the cell details while the ruff check command does:

error: Failed to parse notebooks/syntax_error.ipynb:4:1:5: Invalid decimal integer literal

I can look into it.

@dhruvmanila dhruvmanila added notebook Related to (Jupyter) notebooks cli Related to the command-line interface and removed needs-info More information is needed from the issue author labels May 17, 2024
@dhruvmanila dhruvmanila self-assigned this May 17, 2024
@dhruvmanila dhruvmanila changed the title error: Failed to parse notebook Invalid decimal integer literal Invalid syntax error location for Notebook with ruff format May 17, 2024
@dhruvmanila dhruvmanila added bug Something isn't working and removed cli Related to the command-line interface labels May 17, 2024
@david-waterworth
Copy link
Author

Note the ruff check command isn't really including the cell details either - see below, it has line and column number but not cell number. It works in the vscode "Problems" panel because it's linked, i.e. I can click on the message and it'll jump to the correct cell but the message itself would ideally also contain the cell number (i.e. the first message should have suffix [Cell 24, Line 2, Col 28] if that's possible

image

@dhruvmanila
Copy link
Member

I meant that the output in the CLI does provide the correct cell number:

$ ruff check ~/playground/ruff/notebooks/syntax_error.ipynb 
error: Failed to parse /Users/dhruv/playground/ruff/notebooks/syntax_error.ipynb:4:1:5: Invalid decimal integer literal
/Users/dhruv/playground/ruff/notebooks/syntax_error.ipynb:cell 4:1:5: E999 SyntaxError: Invalid decimal integer literal

Regarding the VS Code problems tab, I don't know if that's even possible. I'll need to look into it.

@david-waterworth
Copy link
Author

Ah right yeah, I don't think it's an issue in the vs code tab, as I mentioned you can click to jump to the problem anyway

@dhruvmanila dhruvmanila linked a pull request May 17, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working notebook Related to (Jupyter) notebooks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants