Skip to content

Commit

Permalink
Fix annotation clobbering __all__ (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Jan 5, 2021
1 parent 650efb9 commit 43541ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pyflakes/checker.py
Expand Up @@ -1140,7 +1140,10 @@ def addBinding(self, node, value):
# then assume the rebound name is used as a global or within a loop
value.used = self.scope[value.name].used

self.scope[value.name] = value
# don't treat annotations as assignments if there is an existing value
# in scope
if value.name not in self.scope or not isinstance(value, Annotation):
self.scope[value.name] = value

def _unknown_handler(self, node):
# this environment variable configures whether to error on unknown
Expand Down
13 changes: 13 additions & 0 deletions pyflakes/test/test_type_annotations.py
Expand Up @@ -335,6 +335,19 @@ def f(t: T): pass
def g(t: 'T'): pass
''')

@skipIf(version_info < (3, 6), 'new in Python 3.6')
def test_type_annotation_clobbers_all(self):
self.flakes('''\
from typing import TYPE_CHECKING, List
from y import z
if not TYPE_CHECKING:
__all__ = ("z",)
else:
__all__: List[str]
''')

def test_typeCommentsMarkImportsAsUsed(self):
self.flakes("""
from mod import A, B, C, D, E, F, G
Expand Down

0 comments on commit 43541ee

Please sign in to comment.