Skip to content

Defining a homogeneous TypedDict #1592

Answered by erictraut
maflAT asked this question in Q&A
Discussion options

You must be logged in to vote

There's currently no way to define that in the type system. There is a draft PEP 728 that would allow for this. The reason that a type checker cannot narrow the type of values and items with today's TypedDict is because other (unspecified) keys may be present in a class that is compatible with a TypedDict. Since these potential other keys have values of an unknown type, they need to be treated as object. PEP 728 would allow you to specify that no other keys can be present.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Akuli
Comment options

@erictraut
Comment options

Answer selected by maflAT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants