Thanks to visit codestin.com
Credit goes to github.com

Skip to content

False negative with walrus operator and comprehension #11060

Description

@melassa

Invalid error for mypy: Name "x" already defined but no problem for Python 3.8:

x = 0
[x := x + y for y in range(2)]

And no problem for mypy, but Python 3.8 error: NameError: name 'z' is not defined:

[z := z + y for y in range(2)]

Tested under Python 3.8 and mypy 0.910

The whole code to test:

# ok for Python but error for mypy: Name "x" already defined
x = 0
[x := x + y for y in range(2)]

# ok for mypy, but Python error: NameError: name 'z' is not defined
[z := z + y for y in range(2)]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-pep-572PEP 572 (walrus operator)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions