Skip to content

Reference

The public API is defined under the root of the reification package.

Usage: from reification import Reified

reification

Reified

Mixin class designed to facilitate the creation of new types based on reified type parameters. In most cases, this class should be placed before the normal generic class in the class inheritance list.

Example

from reification import Reified class ReifiedListT: ... pass xs = ReifiedListint xs.targ

Attributes:

  • targ (type | tuple[type | Any, ...] | Any) –

    The type argument(s) that were specified when the reified generic class was instantiated.

  • type_args (tuple[type | Any, ...]) –

    A tuple containing the type argument(s) provided for the reified generic class.

targ = Any class-attribute

The type argument(s) that were specified when the reified generic class was instantiated.

If there is more than one type argument, targ will be a tuple containing each given type. If no type argument is specified, Any will be returned.

type_args = (Any,) class-attribute

A tuple containing the type argument(s) provided for the reified generic class.

Unlike targ, type_args always returns a tuple of the specified type arguments, even when there's only one type argument. If no type arguments are given, it contains a single Any.

__class_getitem__(params)

This dunder method, which the class overrides, is used for creating a new type each time it is called with distinct type arguments. It serves a key role in handling parameterized generic classes, enabling different identities for different type arguments of the same base class.

Note that this custom method violates Python's convention that __class_getitem__ should return an instance of GenericAlias.