Skip to content

Bug? TypeDict and covariance [NotABug] #8894

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

You must be logged in to vote

Pyright is working correctly here. A TypedDict class is a structural type that defines specific keys and (if they are present) the corresponding value's type. A dictionary can contain additional keys not specified in a TypedDict definition and still be compatible with the TypedDict. That means the value type in the Mapping must be object to account for these possible additional keys. For more details, refer to this portion of the typing spec.

There is a draft PEP 728 that proposes to introduce the concept of a "closed" TypedDict to the Python type system. This PEP hasn't yet been approved by the typing council or the steering council, but pyright implements provisional support for it.

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@bukzor
Comment options

Answer selected by bukzor
Comment options

You must be logged in to vote
4 replies
@erictraut
Comment options

@bukzor
Comment options

@erictraut
Comment options

@bukzor
Comment options

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