Skip to content
Discussion options

You must be logged in to vote

Your implementation includes the type subexpression Union[TResult, Promise[TResult]]. Any time you create a union between a "naked" TypeVar and a type that uses that that same TypeVar as a type argument, you create the potential for multiple solutions within the constraint solver. Consider the following simplified example:

from typing import TypeVar

T = TypeVar("T")

def func(x: T | list[T]) -> T:
    ...

reveal_type(func([1])) # int or list[int]?

In this case, both int and list[int] are acceptable solutions. However, the solution int is probably the one you expect. How does the constraint solver choose between multiple valid answers? There is no standardized technique. Pyright uses a h…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rchl
Comment options

Answer selected by rchl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants