Closed
Description
When a module is used in a type hint in a certain way it will count as using the module in all source files analyzed afterwards. This leads to a false negative for unused-import
depending on the order that sources were scanned.
Steps to reproduce
Given two files, a.py
:
"x"
import uuid
from typing import Optional
ID = None # type: Optional[uuid.UUID]
And b.py
:
"x"
import uuid
Current behavior
When analyzing a.py
then b.py
it misses the unused-import
:
$ pylint a.py b.py
----------------------------------------------------------------------
Your code has been rated at 10.00/10
But swap the order and unused-import
appears:
$ pylint b.py a.py
************* Module b
b.py:2:0: W0611: Unused import uuid (unused-import)
-----------------------------------
Your code has been rated at 7.50/10
Expected behavior
The outputs should be identical and both report unused-import
.
pylint --version output
Result of pylint --version
output:
pylint 2.7.1
astroid 2.5
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0]