Support partial TypedDicts
skeggse opened this issue · comments
Things to check first
- I have searched the existing issues and didn't find my feature already requested there
Feature description
Following up on #376:
There isn't a standard way in Python's type hints system to express that a TypedDict should permit fields other than those explicitly enumerated.
I don't see a reason for the stdlib to add that functionality; my read is that it's largely targeted at static typecheckers like mypy and pyright, and during static analysis you have no reason to model extra fields. For runtime type checking, however, it's very useful to be able to say that a TypedDict
should have this subset of fields, in case an external library adds new fields.
Is there any room in typeguard
to implement a non-standard flag or option to indicate that a TypedDict
should be allowed to have extra fields? Or a place to set a global configuration option?
Use case
This is quite relevant to my use-case, because the third-party in question has been adding a new field basically every week for the past several months. It's looking like typeguard
isn't quite the right tool for the job, though it's helped us catch API regressions too, so I'm a little hesitant to rip it out.
There isn't a standard way in Python's type hints system to express that a TypedDict should permit fields other than those explicitly enumerated.
I don't see a reason for the stdlib to add that functionality;
This is actually a recurring suggestion and there seems to be some interest to add this option. See also https://discuss.python.org/t/add-to-typeddict-new-argument-for-extra-keys/32526.