Repository: PyCQA/pyflakes (python)

Issue:
F811 incorrectly raised for type annotation of imported variable
The following piece of code raises F811 error in pyflakes 2.3.0:
```python
        from django.core.files.storage import default_storage
        default_storage: Storage
        file_path = os.path.join(constants.FILE_FIELD_UPLOAD_DIR_NAME, value.name)
        value = default_storage.save(file_path, value)
```

I am using pyflakes with flake8 and getting this output:
```
F811 redefinition of unused 'default_storage' from line 124
        default_storage: Storage
        ^
1     F811 redefinition of unused 'default_storage' from line 124
```

the code works correctly and `default_storage: Storage` does not redefine the variable, and `default_storage` is used two lines below.

Pull request description:
Annotations no longer redefine names
Resolves #617

Patch:
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 01bcf50..48d3841 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -548,6 +548,10 @@ class Annotation(Binding):
     annotation.
     """
 
+    def redefines(self, other):
+        """An Annotation doesn't define any name, so it cannot redefine one."""
+        return False
+
 
 class FunctionDefinition(Definition):
     pass
diff --git a/tox.ini b/tox.ini
index 37f2b86..c88831a 100644
--- a/tox.ini
+++ b/tox.ini
@@ -8,7 +8,7 @@ deps = flake8==3.6.0
 setenv = PYFLAKES_ERROR_UNKNOWN=1
 commands =
     python --version --version
-    python -m unittest discover pyflakes
+    python -m unittest discover pyflakes {posargs}
     flake8 pyflakes setup.py
 
 [flake8]


Test patch:
diff --git a/pyflakes/test/test_type_annotations.py b/pyflakes/test/test_type_annotations.py
index 9e7ca14..f131034 100644
--- a/pyflakes/test/test_type_annotations.py
+++ b/pyflakes/test/test_type_annotations.py
@@ -283,6 +283,14 @@ class TestTypeAnnotations(TestCase):
         a: 'a: "A"'
         ''', m.ForwardAnnotationSyntaxError)
 
+    @skipIf(version_info < (3, 6), 'new in Python 3.6')
+    def test_annotating_an_import(self):
+        self.flakes('''
+            from a import b, c
+            b: c
+            print(b)
+        ''')
+
     @skipIf(version_info < (3, 6), 'new in Python 3.6')
     def test_unused_annotation(self):
         # Unused annotations are fine in module and class scope