Repository: PyCQA/pyflakes

Issue:
Walrus operator + annotation can cause F821 in version 3.3.0
In order to type hint a variable used in a walrus expression, I put the type hint outside of the expression like in the following example (test.py):

```
a: int
if a := 3:
    print(a)

print(a)
```

Variable "a" is defined in both places

```
$ python3 test.py
3
3
```

In pyflakes version 3.2.0 this produced no errors

```pip install flake8==7.1.2 pyflakes==3.2.0```

```
$ flake8 test.py
```

In pyflakes version 3.3.0 this produces F821 even though "a" is defined

```pip install flake8==7.2.0 pyflakes==3.3.0```

```
$ flake8 test.py
test.py:3:11: F821 undefined name 'a'
test.py:5:7: F821 undefined name 'a'
```

I am on Windows with Python version 3.12.8

Discussion:
@sigmavirus24: Thanks for reporting and fixing! 

Solution patch:
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index c7d3e882..9888d7ac 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -1008,8 +1008,12 @@ def addBinding(self, node, value):
                     for scope in reversed(self.scopeStack)
                     if not isinstance(scope, GeneratorScope)
                 )
-                # it may be a re-assignment to an already existing name
-                scope.setdefault(value.name, value)
+                if value.name in scope and isinstance(scope[value.name], Annotation):
+                    # re-assignment to name that was previously only an annotation
+                    scope[value.name] = value
+                else:
+                    # it may be a re-assignment to an already existing name
+                    scope.setdefault(value.name, value)
             else:
                 self.scope[value.name] = value
 


Test patch:
diff --git a/pyflakes/test/test_other.py b/pyflakes/test/test_other.py
index 68c38e95..23990820 100644
--- a/pyflakes/test/test_other.py
+++ b/pyflakes/test/test_other.py
@@ -1744,6 +1744,13 @@ def test_assign_expr(self):
         print(x)
         ''')
 
+    def test_assign_expr_after_annotation(self):
+        self.flakes("""
+        a: int
+        print(a := 3)
+        print(a)
+        """)
+
     def test_assign_expr_generator_scope(self):
         """Test assignment expressions in generator expressions."""
         self.flakes('''