Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TypedDict and missing keys #1883

Discussion options

Hi. I don't understand why the following causes a Missing keys error?

class ConnectKwargs(TypedDict):
 host: str
 user: str
 port: str
class TransportParams(ConnectKwargs):
 connect_kwargs: ConnectKwargs
 keyfile: str | None
 passphrase: str | None
 
connect_kwargs: ConnectKwargs = {'host':payload['host'], 'user':payload['user'], 'port':payload['port']}
transport_params: TransportParams = {'connect_kwargs':connect_kwargs, 'keyfile':payload['keyfile'], 'passphrase':payload['passphrase']}

error: Missing keys ("host", "user", "port") for TypedDict "TransportParams" [typeddict-item]

You must be logged in to vote

Since TransportParams is a subclass of ConnectKwargs, it inherits all of the keys of ConnectKwargs, more or less the same as if you had written

class TransportParams(TypedDict):
 host: str
 user: str
 port: str
 connect_kwargs: ConnectKwargs
 keyfile: str | None
 passphrase: str | None

See TypedDict - Inheritance from the typing spec for more details.

Replies: 1 comment

Comment options

Since TransportParams is a subclass of ConnectKwargs, it inherits all of the keys of ConnectKwargs, more or less the same as if you had written

class TransportParams(TypedDict):
 host: str
 user: str
 port: str
 connect_kwargs: ConnectKwargs
 keyfile: str | None
 passphrase: str | None

See TypedDict - Inheritance from the typing spec for more details.

You must be logged in to vote
0 replies
Answer selected by dineshbvadhia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /