Skip to content

Walrus operator + annotation can cause F821 in version 3.3.0 #830

@jbjd

Description

@jbjd

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions