Forwarder
pydantic_modelable.forwarder.ModelableForwarder
Forward Modelable registration decorators to another Modelable.
A ModelableForwarder is a registration proxy: every decorator invoked on
it is delegated, unchanged, to a target Modelable. The target then
behaves exactly as if it had been decorated directly, so a third-party
module can register attributes, unions or enums onto a core model it never
imports, by going through a forwarder instead.
Bind a forwarder to its target by subclassing with the forwards_to
keyword:
from pydantic import BaseModel
from pydantic_modelable import Modelable, ModelableForwarder
class Profile(Modelable):
...
class ExtensionForwarder(ModelableForwarder, forwards_to=Profile):
...
# Lands on `Profile` as if `@Profile.as_attribute('indirect')` was used:
@ExtensionForwarder.as_attribute('indirect')
class IndirectExtension(BaseModel):
...
The target may itself be another ModelableForwarder, in which case
forwarders are chained until a concrete Modelable is reached.
as_attribute(attr_name, optional=False, default_factory=None)
classmethod
Forward Modelable.as_attribute to the target.
extends_union(attr_name)
classmethod
Forward Modelable.extends_union to the target.
extends_enum(decorable)
classmethod
Forward Modelable.extends_enum to the target.
rebuilds_model()
classmethod
Forward Modelable.rebuilds_model to the target.