Skip to content

TypedDict has no key when checking for key #8887

Closed
@Dreamsorcerer

Description

@Dreamsorcerer

Minimal test case:

[case testTaggedUnionByKey]
from mypy_extensions import TypedDict
from typing import Union
class A(TypedDict):
    foo: int
class B(TypedDict):
    bar: str
def a(a: Union[A, B]):
    return a["foo"] if "foo" in a else None
[builtins fixtures/tuple.pyi]

The code is checking if the key is present, so this should pass correctly, but instead fails with error: TypedDict "B" has no key 'foo'.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions