modelity.typing
- class modelity.typing.Comparable(*args, **kwargs)
Bases:
ProtocolProtocol describing generic comparable type.
Added in version 0.33.0.
- __abstractmethods__ = frozenset({})
- __init__(*args, **kwargs)
- __parameters__ = ()
- __protocol_attrs__ = {'__ge__', '__gt__', '__le__', '__lt__'}
- classmethod __subclasshook__(other)
Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
- modelity.typing.Deferred
Marker used to to declare field as deferred.
Deferred fields can be initialized with
Unset, but must eventually be set to instance of typeTto pass validation.Added in version 0.35.0.
alias of
Annotated[T|UnsetType, ‘__deferred__’]
- modelity.typing.LooseOptional
An extended
typing.Optionalthat additionally allowsmodelity.unset.UnsetTypeobjects as valid values.This can be used to satisfy static code checking tools, when initializing fields with
modelity.unset.Unsetobject explicitly.Added in version 0.28.0.
- modelity.typing.StrictOptional
An optional that allows the field to be set to either instance of T or not set at all.
It can be used to replace
typing.Optionalfor self-exclusive fields where exactly one can be set. This corresponds to a situation in a JSON object that only one key out of two possible is allowed.Added in version 0.16.0.
alias of
T|UnsetType
- modelity.typing.is_any_optional(typ: Any) bool
Check if given type is any of the optional types supported by Modelity.
- Parameters:
tp – The type to check.
- modelity.typing.is_deferred(typ: Any) bool
Check if given type is a deferred type.
Deferred types in Modelity are used to declare model fields as required but only during validation stage. This means that the field can be unset when model is created, but must later be set to pass validation.
Added in version 0.35.0.
- Parameters:
tp – The type to check.
- modelity.typing.is_loose_optional(typ: Any) bool
Check if given type is
LooseOptional[T].Added in version 0.36.0.
- Parameters:
tp – The type to check.
- modelity.typing.is_optional(typ: Any) bool
Check if given type is
Optional[T].Added in version 0.36.0.
- Parameters:
tp – The type to check.
- modelity.typing.is_strict_optional(typ: Any) bool
Check if given type is
StrictOptional[T].Added in version 0.36.0.
- Parameters:
tp – The type to check.
- modelity.typing.is_unsettable(typ: Any) bool
Check if given type annotation allows
modelity.unset.Unsetas valid value.Added in version 0.35.0.
- Parameters:
typ – The type to investigate.