Typing for a MutableMapping that contains specific key-value pairs #1225
Unanswered
dmi-dmi-dmi
asked this question in
Q&A
Replies: 1 comment 2 replies
-
This sounds like a use case for TypedDict. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a mutable mapping in my code that is being processed in different functions.
Said mapping has some
@property
ies and can hold quite a lot of different key-value pairs but it is guaranteed that it will contain some specific key-value pairs.These specific key-value pairs are given special treatment in processing functions so I would really like to find a way to type it to ensure at least code handling specific key-value pair is correct
In short code looks like this
and I want to make sure mypy understands that
internal_structure['another-fixed-key']
will be an int list giving me warnings if the code inprocess
function treats it as a list of strings, for example.Beta Was this translation helpful? Give feedback.
All reactions