Repository: PyCQA/pyflakes

Issue:
Odd edge-case regression in type annotated `__all__`
I'm not quite sure how to approach fixing this -- it regressed as part of #535 -- CC @srittau 

Here's a simplified example, this is boiled down from numpy's `numpy/typing/__init__.py`

```python
from typing import TYPE_CHECKING, List

from y import z

if not TYPE_CHECKING:
    __all__ = ("z",)
else:
    __all__: List[str]
```

After #535, the type annotation clobbers the `__all__` "`ExportBinding`" which causes it to no longer mark the imports as used

I *think* we can make `Annotated` a `setdefault` on the latest namespace to prevent this?

Discussion:
sigmavirus24: I turned off the app-veyor webhook for pyflakes.
sigmavirus24: Also went to appveyor and deleted this project

Patch:
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 38f8f73..215bd31 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -1140,7 +1140,10 @@ class Checker(object):
             # 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


Test patch:
diff --git a/pyflakes/test/test_type_annotations.py b/pyflakes/test/test_type_annotations.py
index 409238b..835d8d9 100644
--- a/pyflakes/test/test_type_annotations.py
+++ b/pyflakes/test/test_type_annotations.py
@@ -335,6 +335,19 @@ class TestTypeAnnotations(TestCase):
         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