alhambra.classes#

Module Contents#

Classes#

IdentMergeableItem

Base class for protocol classes.

UpdateListD

Abstract base class for generic types.

Serializable

Helper class that provides a standard way to create an ABC using

Attributes#

T_NMI

T

TS

alhambra.classes.T_NMI[source]#
class alhambra.classes.IdentMergeableItem[source]#

Bases: Protocol

Base class for protocol classes.

Protocol classes are defined as:

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...
ident() str[source]#
merge(other: T_NMI) T_NMI[source]#
copy() T_NMI[source]#
alhambra.classes.T[source]#
class alhambra.classes.UpdateListD(initial: Iterable[T_NMI] = tuple())[source]#

Bases: Generic[T_NMI]

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:

class Mapping(Generic[KT, VT]):
    def __getitem__(self, key: KT) -> VT:
        ...
    # Etc.

This class can then be used as follows:

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
    try:
        return mapping[key]
    except KeyError:
        return default
data: dict[str, T_NMI][source]#
__slots__ = ('data',)[source]#
__setitem__(k: str, v: T_NMI)[source]#
__contains__(kv: str) bool[source]#
__getitem__(k: str | SupportsIndex) T_NMI[source]#
__getitem__(k: slice) T
__delitem__(k: str)[source]#
__len__()[source]#
refreshnames()[source]#
add(v: T_NMI)[source]#
__iter__()[source]#
__str__() str[source]#

Return str(self).

__repr__() str[source]#

Return repr(self).

update(d: Iterable[T_NMI])[source]#
aslist() list[T_NMI][source]#
asdict() dict[str, T_NMI][source]#
copy() T[source]#
__add__(other: Iterable[T_NMI]) T[source]#
__iadd__(other: Iterable[T_NMI]) T[source]#
__or__(other: Iterable[T_NMI]) T[source]#
__ior__(other: Iterable[T_NMI]) T[source]#
__sub__(other: Iterable[T_NMI]) T[source]#
search(regex: str, match: Literal[False] = False) T[source]#
search(regex: str, match: Literal[True]) list[tuple[re.Match, T_NMI]]
alhambra.classes.TS[source]#
class alhambra.classes.Serializable[source]#

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

abstract classmethod _deserialize(input: Any) TS[source]#
abstract _serialize() Any[source]#
classmethod from_yaml(*args, **kwargs) TS[source]#
classmethod from_toml(*args, **kwargs) TS[source]#
classmethod from_json(*args, **kwargs) TS[source]#
to_yaml(*args, **kwargs)[source]#
to_json(*args, **kwargs)[source]#
to_toml(*args, **kwargs)[source]#