Skip to content

used-before-def incorrectly flagged when using match/case with a walrus operator #14659

Closed
@euresti

Description

@euresti

Bug Report

When you use a walrus operator in a match statement mypy will complain about an used-before-def for any use of the variable after the first case. (It doesn't complain for the first case)

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.11&gist=f0900514987ceef340db8076b6319cd8

Expected Behavior

I'm pretty sure the code is fine and that there's no way the variable is actually undefined. I also realize that I can rewrite the code to be case 5 as value: to work around the issue. Also, I realize the example is trivial but imagine if the 5 was int().

Actual Behavior

main.py:6: error: Name "result" is used before definition [used-before-def]

Your Environment

  • Mypy version used: mypy 1.0.0 (compiled: yes)
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.11

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions