-
Notifications
You must be signed in to change notification settings - Fork 131
Open
astral-sh/ruff
#21071Labels
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 type
Milestone
Description
Currently, the only type context we have access to when inferring function arguments is the annotated parameter type. However, the call expression annotation is also relevant, e.g.,
def id[T](x: T) -> T:
return x
def _(i: int):
x: list[int | None] = id([i])
reveal_type(x) # revealed (main): list[int | None] | list[Unknown | int] The problem is that we currently infer function arguments before the specializing the function call, and so the type context when inferring the list expression is still a typevar. On the other hand, we use the inferred argument types to infer the specialization, so there's a bit of a circular dependency 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 type