Skip to content

Incorrect type narrowing for TypedDicts using the S in D type guard pattern #10376

@erictraut

Description

@erictraut

The narrowed type in the following example is incorrect:

class A(TypedDict):
    a: int

def func(t: A):
    if "b" in t:
        reveal_type(t) # Should be `A`, not `Never`

We can't eliminate type A based on this check because the TypedDict is not closed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions