-
Notifications
You must be signed in to change notification settings - Fork 127
Open
astral-sh/ruff
#20950Labels
bidirectional inferenceInference of types that takes into account the context of a declared type or expected typeInference of types that takes into account the context of a declared type or expected typebugSomething isn't workingSomething isn't working
Milestone
Description
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
bidirectional inferenceInference of types that takes into account the context of a declared type or expected typeInference of types that takes into account the context of a declared type or expected typebugSomething isn't workingSomething isn't working