@@ -310,11 +310,11 @@ class Binding(object):
310
310
the node that this binding was last used.
311
311
"""
312
312
313
- def __init__ (self , name , source ):
313
+ def __init__ (self , name , source , during_type_checking = False ):
314
314
self .name = name
315
315
self .source = source
316
316
self .used = False
317
- self .during_type_checking = False
317
+ self .during_type_checking = during_type_checking
318
318
319
319
def __str__ (self ):
320
320
return self .name
@@ -1074,6 +1074,8 @@ def addBinding(self, node, value):
1074
1074
break
1075
1075
existing = scope .get (value .name )
1076
1076
1077
+ value .during_type_checking = self ._in_type_checking
1078
+
1077
1079
if (existing and not isinstance (existing , Builtin ) and
1078
1080
not self .differentForks (node , existing .source )):
1079
1081
@@ -1162,15 +1164,15 @@ def handleNodeLoad(self, node):
1162
1164
# alias of other Importation and the alias
1163
1165
# is used, SubImportation also should be marked as used.
1164
1166
n = scope [name ]
1165
- if isinstance (n , Importation ):
1166
- if n . _has_alias () :
1167
- try :
1168
- scope [ n . fullName ]. used = ( self . scope , node )
1169
- except KeyError :
1170
- pass
1171
- if n . during_type_checking and not self . _in_annotation :
1172
- # Only defined during type-checking; this does not count .
1173
- continue
1167
+ if isinstance (n , Importation ) and n . _has_alias () :
1168
+ try :
1169
+ scope [ n . fullName ]. used = ( self . scope , node )
1170
+ except KeyError :
1171
+ pass
1172
+ if n . during_type_checking and not self . _in_annotation :
1173
+ # Only defined during type-checking; this does not count. Real code
1174
+ # (not an annotation) using this binding will not work .
1175
+ continue
1174
1176
except KeyError :
1175
1177
pass
1176
1178
else :
@@ -2131,7 +2133,6 @@ def IMPORT(self, node):
2131
2133
else :
2132
2134
name = alias .asname or alias .name
2133
2135
importation = Importation (name , node , alias .name )
2134
- importation .during_type_checking = self ._in_type_checking
2135
2136
self .addBinding (node , importation )
2136
2137
2137
2138
def IMPORTFROM (self , node ):
@@ -2164,9 +2165,7 @@ def IMPORTFROM(self, node):
2164
2165
self .report (messages .ImportStarUsed , node , module )
2165
2166
importation = StarImportation (module , node )
2166
2167
else :
2167
- importation = ImportationFrom (name , node ,
2168
- module , alias .name )
2169
- importation .during_type_checking = self ._in_type_checking
2168
+ importation = ImportationFrom (name , node , module , alias .name )
2170
2169
self .addBinding (node , importation )
2171
2170
2172
2171
def TRY (self , node ):
0 commit comments