pyright icon indicating copy to clipboard operation
pyright copied to clipboard

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

Open erictraut opened this issue 8 months ago • 0 comments

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.

erictraut avatar Apr 26 '25 19:04 erictraut