@@ -325,6 +325,7 @@ def __init__(self, name, source):
325
325
self .name = name
326
326
self .source = source
327
327
self .used = False
328
+ self .during_type_checking = False
328
329
329
330
def __str__ (self ):
330
331
return self .name
@@ -612,17 +613,6 @@ def _add_to_names(container):
612
613
613
614
class Scope (dict ):
614
615
importStarred = False # set to True when import * is found
615
- # Special key for checking whether a binding is defined only for type checking.
616
- TYPE_CHECKING_ONLY = object ()
617
-
618
- def __init__ (self ):
619
- super (Scope , self ).__init__ (self )
620
- self [self .TYPE_CHECKING_ONLY ] = collections .defaultdict (bool )
621
-
622
- def items (self ):
623
- for key , val in super (Scope , self ).items ():
624
- if key != self .TYPE_CHECKING_ONLY :
625
- yield key , val
626
616
627
617
def __repr__ (self ):
628
618
scope_cls = self .__class__ .__name__
@@ -1129,6 +1119,8 @@ def addBinding(self, node, value):
1129
1119
break
1130
1120
existing = scope .get (value .name )
1131
1121
1122
+ value .during_type_checking = self ._in_type_checking
1123
+
1132
1124
if (existing and not isinstance (existing , Builtin ) and
1133
1125
not self .differentForks (node , existing .source )):
1134
1126
@@ -1230,8 +1222,7 @@ def handleNodeLoad(self, node):
1230
1222
scope [n .fullName ].used = (self .scope , node )
1231
1223
except KeyError :
1232
1224
pass
1233
- if (self .scope [Scope .TYPE_CHECKING_ONLY ][name ]
1234
- and not self ._in_annotation ):
1225
+ if n .during_type_checking and not self ._in_annotation :
1235
1226
# Only defined during type-checking; this does not count. Real code
1236
1227
# (not an annotation) using this binding will not work.
1237
1228
continue
0 commit comments