-
Notifications
You must be signed in to change notification settings - Fork 219
Closed
astral-sh/ruff
#23437Labels
bugSomething isn't workingSomething isn't working
Description
Summary
Consider:
class I0: ...
class I1: ...
class I2: ...
def f(x: tuple[I0, *tuple[I1, ...], I2]):
[a, b, *c] = x
reveal_type(a) # I0
reveal_type(b) # I1
reveal_type(c) # list[I1 | I2]The types we infer for a and c seem correct here. But the type for b seems incorrect. There are three possible scenarios in which this assignment could succeed; I think we need to consider them all and union the types together:
- The middle element "materialises" to a 0-length tuple. In this scenario at runtime,
awould be of typeI0,bwould be of typeI2andcwould be of typelist[Never] - The middle element "materialises" to a tuple of length 1. In this scenario at runtime,
awould be of typeI0,bwould be of typeI1andcwould be of typelist[I2] - The middle element "materialises" to a tuple of length >=2. In this scenario at runtime,
awould be of typeI0,bwould be of typeI1andcwould be of typelist[I1 | I2]
Given these three scenarios in which the assignment could succeed, I think we should be inferring I1 | I2 for b rather than I1.
Version
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working