-
-
Notifications
You must be signed in to change notification settings - Fork 3k
match
crashes on Union of Tuple and non-Tuple
#12533
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
Comments
I have a similar, but slightly different case triggering this. match cast(results.get(table_ref), tuple[str, int | None]):
case _, None:
return f"`{table_ref.undecorated}{m['alias'] or ''}`"
case _, snapshotTime:
return f"`{table_ref.undecorated}{m['alias'] or ''}` FOR SYSTEM_TIME AS OF TIMESTAMP_MILLIS({snapshotTime})"
case None:
return m[0]
case table_info:
raise NotImplementedError(f"Unexpected table info {table_info}") Will try to reduce this test case further when I find some time :/. |
Minimised test case: foo: tuple[int] | None
match foo:
case x,: pass |
Similar if not identical traceback with union of tuples (so not just non-tuple): import ipaddress
from typing import Literal
from typing_extensions import reveal_type
fam = Literal["4", "u"]
myvar: tuple[fam, ipaddress.IPv4Address] | tuple[fam, str] = ("u", "/mysock")
match myvar:
case ("u", socket_path):
reveal_type(socket_path)
case ("4", ip):
reveal_type(ip)
|
With #13514 landing in master, I thought it would be worth trying a development build of mypy which was crashing for me with what I believe to be this bug. I can confirm that mypy no longer crashes, but it also seems to have lost typing information for variables assigned in the I have tried to simplify down my complex scenario to a simple reproducer from typing import Literal, TypeAlias
CreateOp: TypeAlias = tuple[Literal[1], list]
DeleteOp: TypeAlias = tuple[Literal[2], list]
Ops: TypeAlias = list[CreateOp | DeleteOp]
# No issue when Ops isn't a Union
#Ops: TypeAlias = list[CreateOp]
changes: Ops = []
for change in changes:
match change:
case [1, target]:
reveal_type(target)
target.append(1)
Running the above through mypy 0.942 causes a crash, and with master outputs the following:
By switching around the definition of Ops to the commented one, mypy passes and the Revealed type is |
@sparkiegeek FWIW, that sounds exactly like what is pointed out in a TODO in the merged PR, here: |
Possibly, but if it were that, then wouldn't my reproducer have an inferred type of |
Btw, is the project you encountered this on open source? If so, I can add it to https://github.com/hauntsaninja/mypy_primer |
@hauntsaninja The project where I ran into this issue is: https://github.com/bkovitz/FARGish |
Uh oh!
There was an error while loading. Please reload this page.
Crash Report
mypy 0.942 crashes when the match expression in a match statement is a Union of a Tuple type and a non-tuple type.
Traceback
To Reproduce
Notes
If we change the type of the tuple inside the Union to a tuple with no contents specified, like this:
then there is no crash.
This might be due to the same underlying bug as #12532.
Environment
--python-version 3.10 --show-traceback x.py
mypy.ini
(and other config files): (none)The text was updated successfully, but these errors were encountered: