Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Release date: TBA
..
Put bug fixes that should not wait for a new minor version here

* Fixed a false positive for ``unused-import`` where everything
was not analyzed properly inside typing guards.

..
Insert your changelog randomly, it will reduce merge conflicts
(Ie. not necessarily at the end)
Expand Down
10 changes: 5 additions & 5 deletions pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,11 @@ def _assigned_locally(name_node):

def _is_type_checking_import(node: Union[nodes.Import, nodes.ImportFrom]) -> bool:
"""Check if an import node is guarded by a TYPE_CHECKS guard"""
for ancestor in node.node_ancestors():
if isinstance(ancestor, nodes.If):
if ancestor.test.as_string() in TYPING_TYPE_CHECKS_GUARDS:
return True
return False
return any(
isinstance(ancestor, nodes.If)
and ancestor.test.as_string() in TYPING_TYPE_CHECKS_GUARDS
for ancestor in node.node_ancestors()
)


def _has_locals_call_after_node(stmt, scope):
Expand Down