-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Cannot resolve TypeDict into Union *only* when the Union contains an Awaitable #11324
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
I'm seeing pyright fail to type a TypedDict only when it's resolved into a union that includes a third type (in my example, Awaitable[T]). Here is my repro:
from typing import Awaitable, Callable, Generic, TypedDict, TypeVar, Union
T = TypeVar("T")
U = TypeVar("U")
Input = Union[T, Awaitable[T], "Output[T]"]
class Output(Generic[T]):
def apply(self, func: Callable[[T], Input[U]]) -> "Output[U]": ...
class D(TypedDict):
key: str
def accept(x: Input[list[D]]) -> None: ...
# OK: dict literal directly in call has downward type context.
accept([{"key": "v"}])
# ERROR: dict literal inside apply lambda is inferred as dict[str, str], not D.
accept(Output[list[D]]().apply(lambda _: [{"key": "v"}]))The confusing this is that this makes it type-check without errors:
-Input = Union[T, Awaitable[T], "Output[T]"]
+Input = Union[T, "Output[T]"]Full non-erroring code
from typing import Awaitable, Callable, Generic, TypedDict, TypeVar, Union
T = TypeVar("T")
U = TypeVar("U")
Input = Union[T, "Output[T]"]
class Output(Generic[T]):
def apply(self, func: Callable[[T], Input[U]]) -> "Output[U]": ...
class D(TypedDict):
key: str
def accept(x: Input[list[D]]) -> None: ...
# OK: dict literal directly in call has downward type context.
accept([{"key": "v"}])
# ERROR: dict literal inside apply lambda is inferred as dict[str, str], not D.
accept(Output[list[D]]().apply(lambda _: [{"key": "v"}]))This was observed running the pyright CLI at version 1.1.408.
Notes:
mypy --strict (at version 0.931) type-checks both programs without issue.
#10908 implies that these programs should never type-check, but that obviously the case.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working