pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

`tuple[()] | tuple[int, *tuple[int, ...]]` should be equivalent to `tuple[int, ...]`

Open yangdanny97 opened this issue 9 months ago • 1 comments

Describe the Bug

Interesting example posted by @jorenham in https://discuss.python.org/t/unbounded-tuple-unions/92472, thanks!

Related to contextual subtyping + possibly type simplification

Sandbox Link

https://pyrefly.org/sandbox/?code=C4TwDgpgBAogjgBigXisArmANhA2gCgEoBdAKFEljgEYU1MdcBLAO2DIugHEIlUNseVsAA0UAHSSO4bhFr8GQtmIBUPBGVIREALip8JkrTT3x5h8aQDmvPerqTLN6nbkOjxhAH1nXr9oRTRCgAHygecwCoKABiKABbcBA9QFByMTAQACcmKwALYFT0rIgAMyxkqDS0CpTPHzk-bRd9UPC3VCbouMSMwqgM7LyCyqLM0vK+0FS633rAlrCIuhskWISkvUAZclGc-K3R8Yrt6umA+uo-ZyCkRfaoZy713pH+rN3hqoHDyZqgA

yangdanny97 avatar May 19 '25 02:05 yangdanny97

I think this is another case where first-class intersection/negation could be useful

when we match the RHS with each member of the LHS union we could "subtract" the LHS union member from the RHS type

cc @ndmitchell @grievejia

yangdanny97 avatar May 19 '25 02:05 yangdanny97