pyright icon indicating copy to clipboard operation
pyright copied to clipboard

False negative when accessing TypedDict with `extra_items=Never`

Open erictraut opened this issue 8 months ago • 0 comments

When using PEP 728, it's possible to specify extra_items=Never. The PEP indicates that this should be functionally equivalent to closed=True. Pyright fails to generate an error in this case:

from typing import Never
from typing_extensions import TypedDict

class A(TypedDict, extra_items=Never):
    a: int

def func(t: A):
    reveal_type(t["b"])

It does correctly generate an error in this case:

class A(TypedDict, closed=True):
    a: int

def func(t: A):
    reveal_type(t["b"])

erictraut avatar Apr 26 '25 19:04 erictraut