-
Notifications
You must be signed in to change notification settings - Fork 287
TypedDict and missing keys #1883
Answered
by
brianschubert
dineshbvadhia
asked this question in
Q&A
-
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]
Beta Was this translation helpful? Give feedback.
All reactions
Answered by
brianschubert
Nov 8, 2024
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
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Answer selected by
dineshbvadhia
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment