Skip to content

Commit

Permalink
VariableChecker now accounts for attribute lookups in type comments
Browse files Browse the repository at this point in the history
  • Loading branch information
superbobry committed Jun 22, 2021
1 parent 99589b0 commit 015c251
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pylint/checkers/variables.py
Expand Up @@ -1826,6 +1826,10 @@ def _store_type_annotation_node(self, type_annotation):
self._type_annotation_names.append(type_annotation.name)
return

if isinstance(type_annotation, astroid.Attribute):
self._store_type_annotation_node(type_annotation.expr)
return

if not isinstance(type_annotation, astroid.Subscript):
return

Expand Down
13 changes: 13 additions & 0 deletions tests/checkers/unittest_variables.py
Expand Up @@ -191,6 +191,19 @@ def my_method(self) -> MyType:
with self.assertNoMessages():
self.walk(module)

def test_attribute_in_type_comment(self):
"""Ensure attribute lookups in type comments are accounted for.
https://github.com/PyCQA/pylint/issues/4603
"""
module = astroid.parse(
"""
import abc
x = ... # type: abc.ABC
""")
with self.assertNoMessages():
self.walk(module)


class TestVariablesCheckerWithTearDown(CheckerTestCase):

Expand Down

0 comments on commit 015c251

Please sign in to comment.