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

nbqa-pylint cell number does not include markdown cells #860

Open
rabyj opened this issue Aug 14, 2024 · 3 comments
Open

nbqa-pylint cell number does not include markdown cells #860

rabyj opened this issue Aug 14, 2024 · 3 comments

Comments

@rabyj
Copy link

rabyj commented Aug 14, 2024

Issue

When getting warnings from nbqa-pylint, e.g. notebook.ipynb:cell_XX:Y:Z: C0206: Consider iterating with .items() (consider-using-dict-items), the cell number does not refer to the same number as in vscode. cell_XX does not count markdown cells, rendering the message confusing (and way less useful in large notebooks with lots of markdown)

Joining an example notebook as exported script, since github won't allow me to joint it directly.

I run pre-commit run nbqa-pylint on the staged notebook to generate warnings.

System information

OS: Ubuntu 20.04.6 LTS
vscode: 1.92.1
ms-toolsai.jupyter: 2024.7.0
nbqa: 1.8.7
pylint: 2.16.4
pre-commit: 3.0.4

Notebook exported as Python script

# %%
"""Demonstrating a nbqa-pylint issue."""

# %%
a_dict = {"test":1}

# %%
# forced C0206: vscode cell: 3, nbqa-pylint cell: 3
for key in a_dict:
    b = a_dict[key]

# %% [markdown]
# markdown cell: miaw

# %% [markdown]
# markdown cell 2: miaw two, electric boogaloo

# %%
# forced C0206: vscode cell: 6, nbqa-pylint cell: 4
for key in a_dict:
    b = a_dict[key]

# %%
# forced C0206: vscode cell: 7, nbqa-pylint cell: 5
for key in a_dict:
    b = a_dict[key]

Side question I couldn't find an answer to: Is there a way to force nbqa-pylint to show the context of the error and/or cell content, instead of just showing the warning with cell number? I can file it somewhere else (where?) if this is inappropriate.

@MarcoGorelli
Copy link
Collaborator

Hey @rabyj 👋

thanks for taking the time to report this!

in Jupyter Lab, the numbers line up for me:

image

If vscode is showing numbers differently, then maybe we need ask them to reconsider their numbering?

We could introduce an option in nbQA to let the user choose, although:

  • I predict that ruff will subsume nbQA completely before too long (r.i.p. my lockdown project)
  • I don't have much time for this project at the moment so can't really prioritise adding anything new. Happy to review a pull request if you have interest / time though

@rabyj
Copy link
Author

rabyj commented Aug 14, 2024

Thanks for the fast reply @MarcoGorelli

Isn't that the execution number though, which will change a lot when using a notebook? afaik Jupyter Lab does not actually number cells. I'm referring to the number on the bottom right, cell X of Y.

image

@MarcoGorelli
Copy link
Collaborator

true, I think I was assuming that people would be checking notebooks into version control after having done "restart and run all" (say, if they're using notebooks for documentation)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants