Skip to content

Commit 7024743

Browse files
DudeNr33jacobtylerwalls
authored andcommitted
Fix false positive for unused-import when disabling both used-before-assignment and undefined-variable (#6096)
Co-authored-by: Jacob Walls <[email protected]>
1 parent 4213b3c commit 7024743

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Release date: TBA
2727
Closes #6069
2828
Closes #6136
2929

30+
* Fix false positive for ``unused-import`` when disabling both ``used-before-assignment`` and ``undefined-variable``.
31+
32+
Closes #6089
33+
3034
* Narrow the scope of the ``unnecessary-ellipsis`` checker to:
3135
* functions & classes which contain both a docstring and an ellipsis.
3236
* A body which contains an ellipsis ``nodes.Expr`` node & at least one other statement.

doc/whatsnew/2.13.rst

+4
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ Other Changes
132132

133133
Closes #6028
134134

135+
* Fix false positive for ``unused-import`` when disabling both ``used-before-assignment`` and ``undefined-variable``.
136+
137+
Closes #6089
138+
135139
* Fix false positive for ``unnecessary-ellipsis`` when using an ellipsis as a default argument.
136140

137141
Closes #5973

pylint/checkers/variables.py

-9
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,6 @@ def open(self) -> None:
10851085
self._is_undefined_variable_enabled = self.linter.is_message_enabled(
10861086
"undefined-variable"
10871087
)
1088-
self._is_used_before_assignment_enabled = self.linter.is_message_enabled(
1089-
"used-before-assignment"
1090-
)
10911088
self._is_undefined_loop_variable_enabled = self.linter.is_message_enabled(
10921089
"undefined-loop-variable"
10931090
)
@@ -1550,12 +1547,6 @@ def _check_consumer(
15501547

15511548
self._check_late_binding_closure(node)
15521549

1553-
if not (
1554-
self._is_undefined_variable_enabled
1555-
or self._is_used_before_assignment_enabled
1556-
):
1557-
return (VariableVisitConsumerAction.RETURN, found_nodes)
1558-
15591550
defnode = utils.assign_parent(found_nodes[0])
15601551
defstmt = defnode.statement(future=True)
15611552
defframe = defstmt.frame(future=True)
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
"""Test that unused-import is not emitted here when everything else is disabled
22
33
https://github.com/PyCQA/pylint/issues/3445
4+
https://github.com/PyCQA/pylint/issues/6089
45
"""
6+
from math import e, pi
57
from os import environ
68

79
for k, v in environ.items():
810
print(k, v)
11+
12+
13+
class MyClass:
14+
"""For the bug reported in #6089 it is important to use the same names for the class attributes as in the imports."""
15+
16+
e = float(e)
17+
pi = pi

0 commit comments

Comments
 (0)