typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

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

Open max-muoto opened this issue 1 year ago • 3 comments

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.

max-muoto avatar Aug 28 '24 18:08 max-muoto

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.

JelleZijlstra avatar Aug 28 '24 19:08 JelleZijlstra

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.

max-muoto avatar Aug 29 '24 00:08 max-muoto

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.

JelleZijlstra avatar Aug 29 '24 01:08 JelleZijlstra