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

Pylint does not report "unused-import" if there are quotes around type hint #7679

Closed
hofrob opened this issue Oct 26, 2022 · 4 comments
Closed

Comments

@hofrob
Copy link
Contributor

hofrob commented Oct 26, 2022

Bug description

I used hatch to create this example repo (pipx install hatch).

  • clone the example repo: https://github.com/hofrob/pylint-unused-import-quotes
  • execute hatch run pylint -d all -e W0611 test_pylint/ tests/
  • pylint should report an unused import in test_pylint/baz.py
  • remove quotes from type hint in test_pylint.foo.foo_baz function (around bar.SomeClass)
  • execute hatch run pylint -d all -e W0611 test_pylint/ tests/
  • pylint correctly reports an unused import

Those two things should be unrelated I'd say. No idea why quotes (even if they don't make sense) influence an unused import warning in a completely unrelated file.

Configuration

No response

Command used

pylint -d all -e W0611 test_pylint/ tests/

Pylint output

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

Expected behavior

************* Module test_pylint.baz
test_pylint/baz.py:1:0: W0611: Unused bar imported from test_pylint (unused-import)

------------------------------------------------------------------
Your code has been rated at 9.17/10 (previous run: 9.17/10, +0.00)

Pylint version

pylint 2.15.3
astroid 2.12.10
Python 3.10.6 (main, Aug 10 2022, 11:40:04) [GCC 11.3.0]

OS / Environment

  • Ubuntu 22.04
  • hatch env Hatch, version 1.5.0

Additional dependencies

No response

@hofrob hofrob added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Oct 26, 2022
@mbyrnepr2
Copy link
Member

Thanks for the report @hofrob. Unfortunately I can't reproduce it the way you've described (pylint test_pylint/ tests/).

However I do see the behaviour when linting individual modules:
pylint tmp/baz.py tmp/foo.py (import-error in tmp/baz.py)
pylint tmp/foo.py tmp/baz.py (no import-error in tmp/baz.py)
This behaviour is fixed by this MR.

@mbyrnepr2 mbyrnepr2 added Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine Cannot reproduce 🤷 and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine labels Oct 27, 2022
@hofrob
Copy link
Contributor Author

hofrob commented Oct 28, 2022

Thanks! I will take a look later if it fixes what I'm seeing.

However I do see the behaviour when linting individual modules:
pylint tmp/baz.py tmp/foo.py (import-error in tmp/baz.py)
pylint tmp/foo.py tmp/baz.py (no import-error in tmp/baz.py)

This kind of situation is happening a lot recently. I had a docker container where pylint did not show any messages in our CI, but running the exact same container locally showed the correct messages. I'm running into this a lot at work with co-workers executing pylint with different results. Often times the order of paths in the command line changes the outcome, but it's not the same on all machines (even if they use the same docker container).

Is there any issue regarding this? Do other people report something similar? I couldn't find any threads because I don't even know what to look for to be honest.

@Pierre-Sassoulas
Copy link
Member

Is there any issue regarding this? Do other people report something similar? I couldn't find any threads because I don't even know what to look for to be honest.

Yes, there's an issue with multiprocessing and parallelization the hashmap is not implemented on all checkers (#374). Do not use multiprocessing, the increase in performance is negligible anyway (#2525 : the work in astroid to fix this is humongous).

There's also a problem with the order of file given (#689 and #4053)

@hofrob
Copy link
Contributor Author

hofrob commented Oct 30, 2022

This behaviour is fixed by this MR.

Can confirm! All false negatives are fixed now.

Thanks for the helpful feedback!

@hofrob hofrob closed this as completed Oct 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants