Skip to content

TypedDict has no key when checking for key #8887

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'.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions