objectstate.parametric_axes
Parametric Axes Prototype - Arbitrary semantic axes for type construction.
This module prototypes extending type() to support arbitrary axes beyond (B, S). Proof-of-concept for PEP proposal: extending type() with axes= parameter.
In the real CPython implementation, this logic would be in type.__new__ itself, and every class would have __axes__ by default (empty MappingProxyType).
This prototype uses AxesMeta as a stand-in for what type() would do natively. Once any class uses metaclass=AxesMeta, all subclasses inherit it automatically.
- Usage:
from objectstate.parametric_axes import AxesMeta
# One class in hierarchy uses metaclass=AxesMeta class Step(metaclass=AxesMeta):
pass
# All subclasses automatically get axes support (metaclass inherited) class MyStep(Step, axes={“scope”: “/pipeline/step_0”}):
pass
MyStep.__axes__[“scope”] # “/pipeline/step_0”
# Per-key MRO inheritance works automatically class ChildStep(MyStep, axes={“priority”: 1}):
pass
ChildStep.__axes__[“scope”] # “/pipeline/step_0” (inherited) ChildStep.__axes__[“priority”] # 1 (defined here)
Functions
|
Create a type with arbitrary axes - prototype for extended type(). |
|
Get all axes from a type. |
|
Get a specific axis value. |
|
Check if type has a specific axis. |
|
Class decorator that attaches axes metadata. |
Classes
|
Opt-in base class enabling |
|
Metaclass prototype for type() with axes support. |
- class objectstate.parametric_axes.AxesMeta(name: str, bases: tuple, namespace: dict, axes: Dict[str, Any] | None = None, **kwargs)[source]
Metaclass prototype for type() with axes support.
In the real CPython implementation, this logic would be in type.__new__, and every class would have __axes__ = MappingProxyType({}) by default.
This metaclass is the stand-in: once any class uses metaclass=AxesMeta, all subclasses inherit it automatically (standard metaclass inheritance).
- objectstate.parametric_axes.with_axes(**axes: Any) Callable[[type], type][source]
Class decorator that attaches axes metadata.
The decorated class is recreated using
AxesMetaso it gains: -__axes__(MappingProxyType) - convenience attributes (__scope__,__priority__, etc.)
- class objectstate.parametric_axes.AxesBase[source]
Opt-in base class enabling
class Foo(AxesBase, axes={...})syntax.
- objectstate.parametric_axes.axes_type(name: str, bases: tuple, namespace: dict, **axes) type[source]
Create a type with arbitrary axes - prototype for extended type().
- This mimics the proposed signature:
type(name, bases, namespace, **axes)
- Parameters:
name – Class name
bases – Base classes tuple
namespace – Class namespace dict
**axes – Arbitrary axes (scope=, registry=, version=, etc.)
- Returns:
New type with __axes__ containing all axis values
Example
- MyStep = axes_type(“MyStep”, (Step,), {“process”: fn},
scope=”/pipeline/step_0”, registry=step_registry)
MyStep.__axes__[“scope”] # “/pipeline/step_0” MyStep.__scope__ # “/pipeline/step_0” (convenience)