There should be some way to type a dict
as a strict subset of some other TypedDict
#7299
Labels
dict
as a strict subset of some other TypedDict
#7299
I would like to define a Django application configuration in a type safe way, and provide tools which supply app dependencies to components of the application, like a service locator pattern or something. I am developing code to do make this happen.
Here is the outline of an app config class:
Here is an app config instance:
Here is the action base class:
Here is an instance of an action. The action class wants to make use of the ContentConfig bundle, but also identify that it depends only on the loader and validator classes, the better to support the Interface Segregation Principle.
This approach seems to work well so far. However, it is slightly tedious to test this, because we must create an instance of a test-only class that implements the
PublishDependencies
protocol:If not for the problem of extra keys being present at runtime, it would be convenient to make both
PublishDependencies
andContentDependencies
into aTypedDict
, instead, which would allow tests to use simpledict
objects here instead:I seek some way to identify one typed
TypedDict
as a strict subset of another, or else a type-safe way to construct aTypedDict
from a dict which is a strict superset (without duplicating every key in the child dict).The text was updated successfully, but these errors were encountered: