Skip to content

Commit b938b2b

Browse files
committed
Revert "Another solution."
This reverts commit a6f0dd2.
1 parent a6f0dd2 commit b938b2b

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

pyflakes/checker.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ def __init__(self, name, source):
314314
self.name = name
315315
self.source = source
316316
self.used = False
317+
self.during_type_checking = False
317318

318319
def __str__(self):
319320
return self.name
@@ -587,17 +588,6 @@ def _add_to_names(container):
587588

588589
class Scope(dict):
589590
importStarred = False # set to True when import * is found
590-
# Special key for checking whether a binding is defined only for type checking.
591-
TYPE_CHECKING_ONLY = object()
592-
593-
def __init__(self):
594-
super(Scope, self).__init__(self)
595-
self[self.TYPE_CHECKING_ONLY] = collections.defaultdict(bool)
596-
597-
def items(self):
598-
for key, val in super(Scope, self).items():
599-
if key != self.TYPE_CHECKING_ONLY:
600-
yield key, val
601591

602592
def __repr__(self):
603593
scope_cls = self.__class__.__name__
@@ -1084,6 +1074,8 @@ def addBinding(self, node, value):
10841074
break
10851075
existing = scope.get(value.name)
10861076

1077+
value.during_type_checking = self._in_type_checking
1078+
10871079
if (existing and not isinstance(existing, Builtin) and
10881080
not self.differentForks(node, existing.source)):
10891081

@@ -1111,7 +1103,6 @@ def addBinding(self, node, value):
11111103
# then assume the rebound name is used as a global or within a loop
11121104
value.used = self.scope[value.name].used
11131105

1114-
self.scope[Scope.TYPE_CHECKING_ONLY][value.name] = self._in_type_checking
11151106
self.scope[value.name] = value
11161107

11171108
def _unknown_handler(self, node):
@@ -1178,8 +1169,7 @@ def handleNodeLoad(self, node):
11781169
scope[n.fullName].used = (self.scope, node)
11791170
except KeyError:
11801171
pass
1181-
if (self.scope[Scope.TYPE_CHECKING_ONLY][name]
1182-
and not self._in_annotation):
1172+
if n.during_type_checking and not self._in_annotation:
11831173
# Only defined during type-checking; this does not count. Real code
11841174
# (not an annotation) using this binding will not work.
11851175
continue

0 commit comments

Comments
 (0)