You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given that Python does not support expressing a TypedDict that allows extra/unspecified keys, how should one manage dictionaries that have a bunch of keys that aren't relevant to the code that uses them (e.g. come from an external API), and/or where the shape of the dictionary changes relatively frequently by adding new, backwards-compatbile keys (e.g. also from an external API)?
I can imagine using Union[TypeGuardDef, dict[str, Any]], but that makes using values of that type in places that expect only TypeGuardDef/want to access well-defined members of the TypedDict. This isn't a problem in pure Python because we only discover the discrepancy at runtime, which means that there isn't a huge motivation for static typecheckers or Python's core to add this support.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Given that Python does not support expressing a
TypedDict
that allows extra/unspecified keys, how should one manage dictionaries that have a bunch of keys that aren't relevant to the code that uses them (e.g. come from an external API), and/or where the shape of the dictionary changes relatively frequently by adding new, backwards-compatbile keys (e.g. also from an external API)?I can imagine using
Union[TypeGuardDef, dict[str, Any]]
, but that makes using values of that type in places that expect onlyTypeGuardDef
/want to access well-defined members of theTypedDict
. This isn't a problem in pure Python because we only discover the discrepancy at runtime, which means that there isn't a huge motivation for static typecheckers or Python's core to add this support.ref #376
Beta Was this translation helpful? Give feedback.
All reactions