Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected error 'already defined' in function #11390

Closed
TiesWestendorp opened this issue Oct 26, 2021 · 4 comments
Closed

Unexpected error 'already defined' in function #11390

TiesWestendorp opened this issue Oct 26, 2021 · 4 comments
Labels
bug mypy got something wrong

Comments

@TiesWestendorp
Copy link

TiesWestendorp commented Oct 26, 2021

Bug Report

Unexpected error: error: Name "*" already defined in combination with assignment expression and list comprehension.

To Reproduce

Execute mypy on the following snippet:

def func(input: List[int]) -> List[int]:
    running_maximum = input[0] if len(input) > 0 else 0
    return [running_maximum := max(running_maximum, item) for item in input]

Expected Behavior

Since running_maximum is being returned implicitly during each step in the list comprehension, the assignment expression doesn't hide the value of the initial assignment. Hence, there should be no errors.

Actual Behavior

error: Name "running_maximum" already defined

Your Environment

  • Mypy version used: 0.910
  • Python version used: 3.10
  • Operating system and version: Windows 10
@TiesWestendorp TiesWestendorp added the bug mypy got something wrong label Oct 26, 2021
@hauntsaninja
Copy link
Collaborator

Thanks, I already fixed this on master in #11153

@TiesWestendorp
Copy link
Author

Nice, great work in that case. :)

@TiesWestendorp
Copy link
Author

TiesWestendorp commented Oct 27, 2021

How do mypy releases work? When will this be shipped?

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Oct 27, 2021

No idea. The people with the ability to make releases are very busy.

It looks like this landed one or two days after the cutoff for #11158, so I'd post on there asking for it to be cherry-picked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants