python / typeshed

Collection of library stubs for Python, with static types
Other
4.29k stars 1.73k forks source link

Should `TypedDict.items()` return `dict_items[LiteralString, object]`? #12601

Closed max-muoto closed 2 weeks ago

max-muoto commented 2 weeks ago

I think you could make a good argument that TypedDict.items() should return dict_items[LiteralString, object], as all of the keys are known at code initialization time.

JelleZijlstra commented 2 weeks ago

all of the keys are known at code initialization time

That is not true; TypedDicts can contain arbitrary extra keys at runtime. PEP 728 will change this but has not yet been accepted.

max-muoto commented 2 weeks ago

all of the keys are known at code initialization time

That is not true; TypedDicts can contain arbitrary extra keys at runtime. PEP 728 will change this but has not yet been accepted.

I see, how can this occur today without PEP 728? Or are you saying it's likely for PEP 728 to be accepted, so there's no point in pre-empting this.

JelleZijlstra commented 2 weeks ago

Any TypedDict with arbitrary other keys is a static subtype of another TypedDict, so the set of keys you can get from a TypedDict is not statically known.