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

axes_type(name, bases, namespace, **axes)

Create a type with arbitrary axes - prototype for extended type().

get_axes(cls)

Get all axes from a type.

get_axis(cls, name[, default])

Get a specific axis value.

has_axis(cls, name)

Check if type has a specific axis.

with_axes(**axes)

Class decorator that attaches axes metadata.

Classes

AxesBase()

Opt-in base class enabling class Foo(AxesBase, axes={...}) syntax.

AxesMeta(name, bases, namespace[, axes])

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).

static __new__(mcs, name: str, bases: tuple, namespace: dict, axes: Dict[str, Any] | None = None, **kwargs)[source]

Create type with axes metadata and per-key MRO inheritance.

objectstate.parametric_axes.with_axes(**axes: Any) Callable[[type], type][source]

Class decorator that attaches axes metadata.

The decorated class is recreated using AxesMeta so 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)

objectstate.parametric_axes.get_axes(cls: type) Dict[str, Any][source]

Get all axes from a type.

objectstate.parametric_axes.get_axis(cls: type, name: str, default: Any = None) Any[source]

Get a specific axis value.

objectstate.parametric_axes.has_axis(cls: type, name: str) bool[source]

Check if type has a specific axis.