Skip to content

TypedDict.get wrong inference for Unions of Unions of TypedDictΒ #19902

@randolf-scholz

Description

@randolf-scholz

https://mypy-play.net/?mypy=master&python=3.12&gist=c996915858ba060f38d25e978c66544c

from typing import TypedDict, NotRequired

class A(TypedDict):
    key: NotRequired[int]

class B(TypedDict):
    key: NotRequired[int]

class C(TypedDict):
    key: NotRequired[int]

type A_or_B = A | B

def test(d: A_or_B | C) -> None:
    reveal_type(d.get("key"))  # N: Revealed type is "builtins.object"

Output should be int | None. Coincidentally fixed by #19897.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions