-
Couldn't load subscription status.
- Fork 131
Open
astral-sh/ruff
#20950Description
Literal promotion currently recurses down into types to also promote nested types. When doing type inference for generic container literals, this makes sense for unions:
x = 1 if flag else "a"
xs = [x] # list[Unknown | int | str]But it seems wrong to descend into generic types (and possibly other Type variants)? For example:
class Invariant[T]:
x: T
def __init__(self, value: T):
self.x = value
def _(a: Invariant[Literal[1]]):
xs = [a] # list[Unknown | Invariant[int]]Shouldn't we infer list[Unknown | Invariant[Literal[1]]] here?
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working