@@ -321,11 +321,11 @@ class Binding(object):
321
321
the node that this binding was last used.
322
322
"""
323
323
324
- def __init__ (self , name , source ):
324
+ def __init__ (self , name , source , during_type_checking = False ):
325
325
self .name = name
326
326
self .source = source
327
327
self .used = False
328
- self .during_type_checking = False
328
+ self .during_type_checking = during_type_checking
329
329
330
330
def __str__ (self ):
331
331
return self .name
@@ -1119,6 +1119,8 @@ def addBinding(self, node, value):
1119
1119
break
1120
1120
existing = scope .get (value .name )
1121
1121
1122
+ value .during_type_checking = self ._in_type_checking
1123
+
1122
1124
if (existing and not isinstance (existing , Builtin ) and
1123
1125
not self .differentForks (node , existing .source )):
1124
1126
@@ -1213,15 +1215,15 @@ def handleNodeLoad(self, node):
1213
1215
# alias of other Importation and the alias
1214
1216
# is used, SubImportation also should be marked as used.
1215
1217
n = scope [name ]
1216
- if isinstance (n , Importation ):
1217
- if n . _has_alias () :
1218
- try :
1219
- scope [ n . fullName ]. used = ( self . scope , node )
1220
- except KeyError :
1221
- pass
1222
- if n . during_type_checking and not self . _in_annotation :
1223
- # Only defined during type-checking; this does not count .
1224
- continue
1218
+ if isinstance (n , Importation ) and n . _has_alias () :
1219
+ try :
1220
+ scope [ n . fullName ]. used = ( self . scope , node )
1221
+ except KeyError :
1222
+ pass
1223
+ if n . during_type_checking and not self . _in_annotation :
1224
+ # Only defined during type-checking; this does not count. Real code
1225
+ # (not an annotation) using this binding will not work .
1226
+ continue
1225
1227
except KeyError :
1226
1228
pass
1227
1229
else :
@@ -2271,7 +2273,6 @@ def IMPORT(self, node):
2271
2273
else :
2272
2274
name = alias .asname or alias .name
2273
2275
importation = Importation (name , node , alias .name )
2274
- importation .during_type_checking = self ._in_type_checking
2275
2276
self .addBinding (node , importation )
2276
2277
2277
2278
def IMPORTFROM (self , node ):
@@ -2306,7 +2307,6 @@ def IMPORTFROM(self, node):
2306
2307
else :
2307
2308
importation = ImportationFrom (name , node ,
2308
2309
module , alias .name )
2309
- importation .during_type_checking = self ._in_type_checking
2310
2310
self .addBinding (node , importation )
2311
2311
2312
2312
def TRY (self , node ):
0 commit comments