marsh.schema.namespace
¶
This module creates support for inheritance-based type matching.
For all types in a namespace each subclass of a type being that is being unmarshaled is considered.
- class Namespace(name, base)[source]¶
Holds a group of subclasses for a base class which are each associated with a name.
This class should be initialized via
Namespaces.new()
.Includes functionality for matching a type against the classes held by this namespace. This functionality is cached for improved performance.
- find_subclasses_iter(cls)[source]¶
Yield names of components in this namespace that are subclasses of the input type.
This method provides results for the same but cached method
find_subclasses()
.
- find_subclasses(cls)[source]¶
Get the names of all classes held by this namespace that are subclasses of the input.
- Parameters:
- Return type:
- Returns:
The names of the subclasses.
- register(component: Type[_T], *, name: str, replace: bool = False) Type[_T] [source]¶
- register(*, name: str, replace: bool = False) Callable[[Type[_T]], Type[_T]]
Register a new type for this namespace.
- build(element: Union[None, int, float, bool, str, Sequence[Any], Mapping[str, Any]] = marsh.MISSING, *, name: str) _T [source]¶
- build(element: Optional[Sequence[ElementType]] = marsh.MISSING, *args, name: str) _T
- build(element: Optional[Mapping[str, ElementType]] = marsh.MISSING, *, name: str, **kwargs) _T
Unmarshal a type held by this namespace.
- Return type:
TypeVar
(_T
)
- class Namespaces[source]¶
Singleton class holding all namespaces.
Includes functionality for matching a type against the classes of all namespaces. These matching functions are cached for improved performance.
- find_subclasses_iter(cls)[source]¶
Yield results from finding subclasses of an input type in all namespaces.
This method provides results for the same but cached method
find_subclasses()
.
- find_namespaces_iter(cls)[source]¶
Yield results from finding namespaces matching an input type.
This method provides results for the same but cached method
find_namespaces()
.
- new(name, base)[source]¶
Create a new namespace.
The created namespace has functions for registering new items and building them.
- cache_info(full: Literal[True]) Namespaces.FullCacheInfo [source]¶
- cache_info() Namespaces.CacheInfo
Get info for the cache of this class.
- Parameters:
full (
bool
) – IfTrue
, return the cache info for all namespaces as well.- Return type:
- Returns:
The cache info.
- find_class(cls)[source]¶
Search through all namespaces and return the name of the first class that equals the given type.
- find_subclasses(cls)[source]¶
Search for all subclasses of the given type.
- Argument:
cls: The type to find subclasses for.
- Return type:
- Returns:
Iterable of names and namespaces.
- Parameters:
cls (Any) –