File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -720,14 +720,24 @@ def _bare_name_is_attr(name):
720720
721721 return False
722722
723+ def _module_scope_is_typing (name ):
724+ for scope in reversed (scope_stack ):
725+ if name in scope :
726+ return (
727+ isinstance (scope [name ], Importation ) and
728+ scope [name ].fullName in TYPING_MODULES
729+ )
730+
731+ return False
732+
723733 return (
724734 (
725735 isinstance (node , ast .Name ) and
726736 _bare_name_is_attr (node .id )
727737 ) or (
728738 isinstance (node , ast .Attribute ) and
729739 isinstance (node .value , ast .Name ) and
730- node .value .id in TYPING_MODULES and
740+ _module_scope_is_typing ( node .value .id ) and
731741 is_name_match_fn (node .attr )
732742 )
733743 )
Original file line number Diff line number Diff line change @@ -121,6 +121,23 @@ def f(self, x): # type: (str) -> str
121121 def f(self, x): return x
122122 """ )
123123
124+ def test_aliased_import (self ):
125+ """Detect when typing is imported as another name"""
126+ self .flakes ("""
127+ import typing as t
128+
129+ @t.overload
130+ def f(s): # type: (None) -> None
131+ pass
132+
133+ @t.overload
134+ def f(s): # type: (int) -> int
135+ pass
136+
137+ def f(s):
138+ return s
139+ """ )
140+
124141 def test_not_a_typing_overload (self ):
125142 """regression test for @typing.overload detection bug in 2.1.0"""
126143 self .flakes ("""
You can’t perform that action at this time.
0 commit comments