Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Open
Description
Bug Report
When usingmatch on a tuple of optionals, Mypy doesn't seem to:
- Narrow the type from
Optional[T]toTin non-optional cases, even if all theNonecases have been handled. - Recognize that the match is exhaustive.
This feels similar to#12267 (comment), or maybe#12364 or#13989, but the example is a little different; apologies if it's a dupe / already known—and thanks for taking a look!
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.11&gist=b6c10a27006d7b5ad55729467c2c5de8
Expected Behavior
No errors. 😊
I've used this match-on-a-tuple pattern inRust andSwift a few times, which is why I was a little surprised that Mypy didn't like it.
Actual Behavior
main.py:4: error: Missing return statement [return]main.py:9: error: Item "None" of "Optional[str]" has no attribute "encode" [union-attr]Your Environment
- Mypy version used: 1.0.0
- Python version used: 3.11