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

False positive for ruff INP001 #795

Open
sbrugman opened this issue Feb 15, 2023 · 3 comments
Open

False positive for ruff INP001 #795

sbrugman opened this issue Feb 15, 2023 · 3 comments

Comments

@sbrugman
Copy link
Contributor

sbrugman commented Feb 15, 2023

nbqa ruff checks if the file is part of an implicit namespace package. Part of the check is that it checks if the file has the .py extension: code. It seems that in nbqa this results in false positives - correct me if wrong.

Of course we can just exclude this rule when running ruff in nbqa - but perhaps there is a structural fix that does not require additional configuration for users (e.g. maintain the .ipynb extensions).

Alternatively, we can document this behaviour under known limitations.

@MarcoGorelli
Copy link
Collaborator

hey @sbrugman , thanks for reporting!

I couldn't reproduce this

(.venv) marcogorelli@DESKTOP-U8OKFP3:~/tmp$ pip install -U nbqa ruff
Requirement already satisfied: nbqa in ./.venv/lib/python3.8/site-packages (1.6.1)
Requirement already satisfied: ruff in ./.venv/lib/python3.8/site-packages (0.0.246)
Requirement already satisfied: ipython>=7.8.0 in ./.venv/lib/python3.8/site-packages (from nbqa) (8.6.0)
Requirement already satisfied: tokenize-rt>=3.2.0 in ./.venv/lib/python3.8/site-packages (from nbqa) (5.0.0)
Requirement already satisfied: tomli in ./.venv/lib/python3.8/site-packages (from nbqa) (2.0.1)
Requirement already satisfied: pickleshare in ./.venv/lib/python3.8/site-packages (from ipython>=7.8.0->nbqa) (0.7.5)
Requirement already satisfied: traitlets>=5 in ./.venv/lib/python3.8/site-packages (from ipython>=7.8.0->nbqa) (5.5.0)
Requirement already satisfied: jedi>=0.16 in ./.venv/lib/python3.8/site-packages (from ipython>=7.8.0->nbqa) (0.18.2)
Requirement already satisfied: backcall in ./.venv/lib/python3.8/site-packages (from ipython>=7.8.0->nbqa) (0.2.0)
Requirement already satisfied: prompt-toolkit<3.1.0,>3.0.1 in ./.venv/lib/python3.8/site-packages (from ipython>=7.8.0->nbqa) (3.0.33)
Requirement already satisfied: pygments>=2.4.0 in ./.venv/lib/python3.8/site-packages (from ipython>=7.8.0->nbqa) (2.13.0)
Requirement already satisfied: decorator in ./.venv/lib/python3.8/site-packages (from ipython>=7.8.0->nbqa) (5.1.1)
Requirement already satisfied: pexpect>4.3 in ./.venv/lib/python3.8/site-packages (from ipython>=7.8.0->nbqa) (4.8.0)
Requirement already satisfied: matplotlib-inline in ./.venv/lib/python3.8/site-packages (from ipython>=7.8.0->nbqa) (0.1.6)
Requirement already satisfied: stack-data in ./.venv/lib/python3.8/site-packages (from ipython>=7.8.0->nbqa) (0.6.1)
Requirement already satisfied: parso<0.9.0,>=0.8.0 in ./.venv/lib/python3.8/site-packages (from jedi>=0.16->ipython>=7.8.0->nbqa) (0.8.3)
Requirement already satisfied: ptyprocess>=0.5 in ./.venv/lib/python3.8/site-packages (from pexpect>4.3->ipython>=7.8.0->nbqa) (0.7.0)
Requirement already satisfied: wcwidth in ./.venv/lib/python3.8/site-packages (from prompt-toolkit<3.1.0,>3.0.1->ipython>=7.8.0->nbqa) (0.2.5)
Requirement already satisfied: executing>=1.2.0 in ./.venv/lib/python3.8/site-packages (from stack-data->ipython>=7.8.0->nbqa) (1.2.0)
Requirement already satisfied: pure-eval in ./.venv/lib/python3.8/site-packages (from stack-data->ipython>=7.8.0->nbqa) (0.2.2)
Requirement already satisfied: asttokens>=2.1.0 in ./.venv/lib/python3.8/site-packages (from stack-data->ipython>=7.8.0->nbqa) (2.1.0)
Requirement already satisfied: six in ./.venv/lib/python3.8/site-packages (from asttokens>=2.1.0->stack-data->ipython>=7.8.0->nbqa) (1.16.0)

[notice] A new release of pip available: 22.3.1 -> 23.0
[notice] To update, run: pip install --upgrade pip
(.venv) marcogorelli@DESKTOP-U8OKFP3:~/tmp$ nbqa ruff notebook_for_testing.ipynb
notebook_for_testing.ipynb:cell_1:1:8: F401 [*] `os` imported but unused
notebook_for_testing.ipynb:cell_1:3:8: F401 [*] `glob` imported but unused
notebook_for_testing.ipynb:cell_1:5:8: F401 [*] `nbqa` imported but unused
notebook_for_testing.ipynb:cell_4:1:1: E402 Module level import not at top of file
notebook_for_testing.ipynb:cell_4:1:20: F401 [*] `random.randint` imported but unused
notebook_for_testing.ipynb:cell_5:1:1: E402 Module level import not at top of file
notebook_for_testing.ipynb:cell_5:2:1: E402 Module level import not at top of file
Found 7 errors.
[*] 4 potentially fixable with the --fix option.

Which option should I pass to reproduce this?

@sbrugman
Copy link
Contributor Author

This occurred on https://GitHub.com/ing-bank/popmon in the directory popmon/notebooks. I'll make a minimal reproducible example (can take a day or two)

@MarcoGorelli
Copy link
Collaborator

sure! I'll take a look when you post it - I really like ruff so am keen to get this integration right

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