False positive: Incompatible types in capture pattern (pattern captures type "Exception", variable has type <deleted>) #18752
Labels
bug
mypy got something wrong
topic-error-reporting
How we report errors
topic-match-statement
Python 3.10's match statement
Bug Report
When trying to use a
match
pattern and bind to a variable with the same name as anexcept ... as
bind, mypy starts returning an error.If I remove the
try/except
block or don't try to attempt to reassign the variable, the issue goes away.I've tried to search for other similar issues, but couldn't find much. Hope it's not a duplicate.
To Reproduce
Gist URL: https://gist.github.com/mypy-play/4d9bc9f42141eb6093823efcbc0dafd7
Playground URL: https://mypy-play.net/?mypy=master&python=3.13&gist=4d9bc9f42141eb6093823efcbc0dafd7&flags=allow-redefinition
Tried with various versions of mypy (1.8.0, 1.15.0, master) and Python (3.10, 3.11, 3.13).
Tried with
--allow-redefinition
and without.Expected Behavior
No error from mypy, at least when using
--allow-redefinition
.Actual Behavior
Your Environment
mypy.ini
(and other config files): N/AThe text was updated successfully, but these errors were encountered: