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

Reusing variable previously defined with walrus operator triggers used-before-def error #14626

Closed
goldenfire6 opened this issue Feb 6, 2023 · 1 comment · Fixed by #14646
Closed
Labels
bug mypy got something wrong topic-pep-572 PEP 572 (walrus operator) topic-possibly-undefined possibly-undefined error code

Comments

@goldenfire6
Copy link

To Reproduce

x = 3
z = (y := str(x)).index(y.lower())

Expected Behavior

Should be no errors -- this code does not error using mypy v0.991 or prior, so this seems to be a new issue with v1.0.0.

Actual Behavior

error: Name "y" is used before definition [used-before-def]

Your Environment

  • Mypy version used: 1.0.0
  • Mypy command-line flags: none
  • Python version used: 3.9
@goldenfire6 goldenfire6 added the bug mypy got something wrong label Feb 6, 2023
@hauntsaninja hauntsaninja added the topic-possibly-undefined possibly-undefined error code label Feb 6, 2023
@AlexWaygood AlexWaygood added the topic-pep-572 PEP 572 (walrus operator) label Feb 7, 2023
@hauntsaninja hauntsaninja mentioned this issue Feb 7, 2023
17 tasks
@ilinum
Copy link
Collaborator

ilinum commented Feb 8, 2023

Thanks for reporting! We will include the fix in the 1.0.1 release.

JukkaL pushed a commit that referenced this issue Feb 8, 2023
Fixes #14626.

I believe changing the way that we analyze call expression makes sense
(first, we analyze the callee, then we analyze the arguments).
ilinum added a commit to ilinum/mypy that referenced this issue Feb 8, 2023
Fixes python#14626.

I believe changing the way that we analyze call expression makes sense
(first, we analyze the callee, then we analyze the arguments).
ilinum added a commit to ilinum/mypy that referenced this issue Feb 8, 2023
Fixes python#14626.

I believe changing the way that we analyze call expression makes sense
(first, we analyze the callee, then we analyze the arguments).
ilinum added a commit that referenced this issue Feb 9, 2023
#14654)

Fixes #14626.

I believe changing the way that we analyze call expression makes sense
(first, we analyze the callee, then we analyze the arguments).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-pep-572 PEP 572 (walrus operator) topic-possibly-undefined possibly-undefined error code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants