-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongtopic-match-statementPython 3.10's match statementPython 3.10's match statement
Description
Bug Report
match can't determine type of an element of a tuple guarded with isinstance, if the variable holding the tuple has type Any.
To Reproduce
from typing import Any
e: Any = ('x',)
match e:
case (a,) if isinstance(a, str):
print('HERE', e)
Expected Behavior
This code should pass type-check. mypy should be able to determine the type of "a" because the isinstance guard implies that "a" must be a str.
Actual Behavior
$ mypy --python-version 3.10 x.py
x.py:5: error: Cannot determine type of "a"
Found 1 error in 1 file (checked 1 source file)
Variations
If e is given no declared type, like this:
e = ('x',)
then mypy reports no errors.
If e is declared to be a tuple whose members are unspecified, like this:
e: Tuple = ('x',)
then mypy reports no errors.
Environment
- Mypy version used: 0.942
- Mypy command-line flags:
--python-version 3.10 x.py - Mypy configuration options from
mypy.ini(and other config files): (none) - Python version used: 3.10.2
- Operating system and version: Ubuntu 18.04
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-match-statementPython 3.10's match statementPython 3.10's match statement