Skip to content

Commit

Permalink
Fix false positive for unused-import when disabling both ``used-b…
Browse files Browse the repository at this point in the history
…efore-assignment`` and ``undefined-variable`` (#6096)

Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
  • Loading branch information
2 people authored and Pierre-Sassoulas committed Apr 4, 2022
1 parent 4213b3c commit 7024743
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -27,6 +27,10 @@ Release date: TBA
Closes #6069
Closes #6136

* Fix false positive for ``unused-import`` when disabling both ``used-before-assignment`` and ``undefined-variable``.

Closes #6089

* Narrow the scope of the ``unnecessary-ellipsis`` checker to:
* functions & classes which contain both a docstring and an ellipsis.
* A body which contains an ellipsis ``nodes.Expr`` node & at least one other statement.
Expand Down
4 changes: 4 additions & 0 deletions doc/whatsnew/2.13.rst
Expand Up @@ -132,6 +132,10 @@ Other Changes

Closes #6028

* Fix false positive for ``unused-import`` when disabling both ``used-before-assignment`` and ``undefined-variable``.

Closes #6089

* Fix false positive for ``unnecessary-ellipsis`` when using an ellipsis as a default argument.

Closes #5973
Expand Down
9 changes: 0 additions & 9 deletions pylint/checkers/variables.py
Expand Up @@ -1085,9 +1085,6 @@ def open(self) -> None:
self._is_undefined_variable_enabled = self.linter.is_message_enabled(
"undefined-variable"
)
self._is_used_before_assignment_enabled = self.linter.is_message_enabled(
"used-before-assignment"
)
self._is_undefined_loop_variable_enabled = self.linter.is_message_enabled(
"undefined-loop-variable"
)
Expand Down Expand Up @@ -1550,12 +1547,6 @@ def _check_consumer(

self._check_late_binding_closure(node)

if not (
self._is_undefined_variable_enabled
or self._is_used_before_assignment_enabled
):
return (VariableVisitConsumerAction.RETURN, found_nodes)

defnode = utils.assign_parent(found_nodes[0])
defstmt = defnode.statement(future=True)
defframe = defstmt.frame(future=True)
Expand Down
@@ -1,8 +1,17 @@
"""Test that unused-import is not emitted here when everything else is disabled
https://github.com/PyCQA/pylint/issues/3445
https://github.com/PyCQA/pylint/issues/6089
"""
from math import e, pi
from os import environ

for k, v in environ.items():
print(k, v)


class MyClass:
"""For the bug reported in #6089 it is important to use the same names for the class attributes as in the imports."""

e = float(e)
pi = pi

0 comments on commit 7024743

Please sign in to comment.