Repository: PyCQA/pyflakes (python)

Issue:
Regression with version 3.0 ('bool' object is not subscriptable)
Hello! I found a regression with version 3.0

This snippet:
```
test: int

test.__dict__


def fn():
    test = 1
```

Raises the following exception with version 3.0.1:
```
Traceback (most recent call last):
  File "/opt/homebrew/bin/pyflakes", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/lib/python3.10/site-packages/pyflakes/api.py", line 182, in main
    warnings = checkRecursive(args, reporter)
  File "/opt/homebrew/lib/python3.10/site-packages/pyflakes/api.py", line 127, in checkRecursive
    warnings += checkPath(sourcePath, reporter)
  File "/opt/homebrew/lib/python3.10/site-packages/pyflakes/api.py", line 71, in checkPath
    return check(codestr, filename, reporter)
  File "/opt/homebrew/lib/python3.10/site-packages/pyflakes/api.py", line 47, in check
    w = checker.Checker(tree, filename=filename)
  File "/opt/homebrew/lib/python3.10/site-packages/pyflakes/checker.py", line 789, in __init__
    self.runDeferred(self._deferredFunctions)
  File "/opt/homebrew/lib/python3.10/site-packages/pyflakes/checker.py", line 832, in runDeferred
    handler()
  File "/opt/homebrew/lib/python3.10/site-packages/pyflakes/checker.py", line 1998, in runFunction
    self.handleChildren(node, omit=['decorator_list', 'returns'])
  File "/opt/homebrew/lib/python3.10/site-packages/pyflakes/checker.py", line 1238, in handleChildren
    self.handleNode(node, tree)
  File "/opt/homebrew/lib/python3.10/site-packages/pyflakes/checker.py", line 1283, in handleNode
    handler(node)
  File "/opt/homebrew/lib/python3.10/site-packages/pyflakes/checker.py", line 1238, in handleChildren
    self.handleNode(node, tree)
  File "/opt/homebrew/lib/python3.10/site-packages/pyflakes/checker.py", line 1283, in handleNode
    handler(node)
  File "/opt/homebrew/lib/python3.10/site-packages/pyflakes/checker.py", line 1889, in NAME
    self.handleNodeStore(node)
  File "/opt/homebrew/lib/python3.10/site-packages/pyflakes/checker.py", line 1163, in handleNodeStore
    if used and used[0] is self.scope and name not in self.scope.globals:
TypeError: 'bool' object is not subscriptable
```

But it is correctly handled by version 2.5.0, that returns the correct errors:

```
test.py:3:1: undefined name 'test'
test.py:7:5: local variable 'test' is assigned to but never used
```

The snippet does not cause exceptions when any part of it is removed (for example the type annotation or the `test.__dict__` or the assignment in the function)


Pull request description:
fix accessed global annotation being redefined in a local scope
resolves #764

Patch:
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 4d778a8..e654afa 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -1068,7 +1068,7 @@ class Checker:
 
             binding = scope.get(name, None)
             if isinstance(binding, Annotation) and not self._in_postponed_annotation:
-                scope[name].used = True
+                scope[name].used = (self.scope, node)
                 continue
 
             if name == 'print' and isinstance(binding, Builtin):


Test patch:
diff --git a/pyflakes/test/test_type_annotations.py b/pyflakes/test/test_type_annotations.py
index f0fd3b9..396d676 100644
--- a/pyflakes/test/test_type_annotations.py
+++ b/pyflakes/test/test_type_annotations.py
@@ -367,6 +367,13 @@ class TestTypeAnnotations(TestCase):
             x = 3
         ''', m.UnusedVariable)
 
+    def test_unused_annotation_in_outer_scope_reassigned_in_local_scope(self):
+        self.flakes('''
+        x: int
+        x.__dict__
+        def f(): x = 1
+        ''', m.UndefinedName, m.UnusedVariable)
+
     def test_unassigned_annotation_is_undefined(self):
         self.flakes('''
         name: str