Skip to content

dyce.h package reference

HAbleOpsMixin

A “mix-in” class providing arithmetic operations for implementers of the HAbleT protocol. The P class derives from this class.

__abs__(self: HAbleT) -> H special

Shorthand for operator.__abs__(self.h()). See the h method.

Source code in dyce/h.py
def __abs__(self: HAbleT) -> H:
    r"""
    Shorthand for ``#!python operator.__abs__(self.h())``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __abs__(self.h())

__add__(self: HAbleT, other: _OperandT) -> H special

Shorthand for operator.__add__(self.h(), other). See the h method.

Source code in dyce/h.py
def __add__(self: HAbleT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python operator.__add__(self.h(), other)``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __add__(self.h(), other)

__and__(self: HAbleT, other: Union[IntT, H, HAbleT]) -> H special

Shorthand for operator.__and__(self.h(), other). See the h method.

Source code in dyce/h.py
def __and__(self: HAbleT, other: Union[IntT, H, HAbleT]) -> H:
    r"""
    Shorthand for ``#!python operator.__and__(self.h(), other)``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __and__(self.h(), other)

__floordiv__(self: HAbleT, other: _OperandT) -> H special

Shorthand for operator.__floordiv__(self.h(), other). See the h method.

Source code in dyce/h.py
def __floordiv__(self: HAbleT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python operator.__floordiv__(self.h(), other)``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __floordiv__(self.h(), other)

__invert__(self: HAbleT) -> H special

Shorthand for operator.__invert__(self.h()). See the h method.

Source code in dyce/h.py
def __invert__(self: HAbleT) -> H:
    r"""
    Shorthand for ``#!python operator.__invert__(self.h())``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __invert__(self.h())

__mod__(self: HAbleT, other: _OperandT) -> H special

Shorthand for operator.__mod__(self.h(), other). See the h method.

Source code in dyce/h.py
def __mod__(self: HAbleT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python operator.__mod__(self.h(), other)``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __mod__(self.h(), other)

__mul__(self: HAbleT, other: _OperandT) -> H special

Shorthand for operator.__mul__(self.h(), other). See the h method.

Source code in dyce/h.py
def __mul__(self: HAbleT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python operator.__mul__(self.h(), other)``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __mul__(self.h(), other)

__neg__(self: HAbleT) -> H special

Shorthand for operator.__neg__(self.h()). See the h method.

Source code in dyce/h.py
def __neg__(self: HAbleT) -> H:
    r"""
    Shorthand for ``#!python operator.__neg__(self.h())``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __neg__(self.h())

__or__(self: HAbleT, other: Union[IntT, H, HAbleT]) -> H special

Shorthand for operator.__or__(self.h(), other). See the h method.

Source code in dyce/h.py
def __or__(self: HAbleT, other: Union[IntT, H, HAbleT]) -> H:
    r"""
    Shorthand for ``#!python operator.__or__(self.h(), other)``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __or__(self.h(), other)

__pos__(self: HAbleT) -> H special

Shorthand for operator.__pos__(self.h()). See the h method.

Source code in dyce/h.py
def __pos__(self: HAbleT) -> H:
    r"""
    Shorthand for ``#!python operator.__pos__(self.h())``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __pos__(self.h())

__pow__(self: HAbleT, other: _OperandT) -> H special

Shorthand for operator.__pow__(self.h(), other). See the h method.

Source code in dyce/h.py
def __pow__(self: HAbleT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python operator.__pow__(self.h(), other)``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __pow__(self.h(), other)

__radd__(self: HAbleT, other: OutcomeT) -> H special

Shorthand for operator.__add__(other, self.h()). See the h method.

Source code in dyce/h.py
def __radd__(self: HAbleT, other: OutcomeT) -> H:
    r"""
    Shorthand for ``#!python operator.__add__(other, self.h())``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __add__(other, self.h())

__rand__(self: HAbleT, other: IntT) -> H special

Shorthand for operator.__and__(other, self.h()). See the h method.

Source code in dyce/h.py
def __rand__(self: HAbleT, other: IntT) -> H:
    r"""
    Shorthand for ``#!python operator.__and__(other, self.h())``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __and__(other, self.h())

__rfloordiv__(self: HAbleT, other: OutcomeT) -> H special

Shorthand for operator.__floordiv__(other, self.h()). See the h method.

Source code in dyce/h.py
def __rfloordiv__(self: HAbleT, other: OutcomeT) -> H:
    r"""
    Shorthand for ``#!python operator.__floordiv__(other, self.h())``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __floordiv__(other, self.h())

__rmod__(self: HAbleT, other: OutcomeT) -> H special

Shorthand for operator.__mod__(other, self.h()). See the h method.

Source code in dyce/h.py
def __rmod__(self: HAbleT, other: OutcomeT) -> H:
    r"""
    Shorthand for ``#!python operator.__mod__(other, self.h())``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __mod__(other, self.h())

__rmul__(self: HAbleT, other: OutcomeT) -> H special

Shorthand for operator.__mul__(other, self.h()). See the h method.

Source code in dyce/h.py
def __rmul__(self: HAbleT, other: OutcomeT) -> H:
    r"""
    Shorthand for ``#!python operator.__mul__(other, self.h())``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __mul__(other, self.h())

__ror__(self: HAbleT, other: IntT) -> H special

Shorthand for operator.__or__(other, self.h()). See the h method.

Source code in dyce/h.py
def __ror__(self: HAbleT, other: IntT) -> H:
    r"""
    Shorthand for ``#!python operator.__or__(other, self.h())``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __or__(other, self.h())

__rpow__(self: HAbleT, other: OutcomeT) -> H special

Shorthand for operator.__pow__(other, self.h()). See the h method.

Source code in dyce/h.py
def __rpow__(self: HAbleT, other: OutcomeT) -> H:
    r"""
    Shorthand for ``#!python operator.__pow__(other, self.h())``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __pow__(other, self.h())

__rsub__(self: HAbleT, other: OutcomeT) -> H special

Shorthand for operator.__sub__(other, self.h()). See the h method.

Source code in dyce/h.py
def __rsub__(self: HAbleT, other: OutcomeT) -> H:
    r"""
    Shorthand for ``#!python operator.__sub__(other, self.h())``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __sub__(other, self.h())

__rtruediv__(self: HAbleT, other: OutcomeT) -> H special

Shorthand for operator.__truediv__(other, self.h()). See the h method.

Source code in dyce/h.py
def __rtruediv__(self: HAbleT, other: OutcomeT) -> H:
    r"""
    Shorthand for ``#!python operator.__truediv__(other, self.h())``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __truediv__(other, self.h())

__rxor__(self: HAbleT, other: IntT) -> H special

Shorthand for operator.__xor__(other, self.h()). See the h method.

Source code in dyce/h.py
def __rxor__(self: HAbleT, other: IntT) -> H:
    r"""
    Shorthand for ``#!python operator.__xor__(other, self.h())``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __xor__(other, self.h())

__sub__(self: HAbleT, other: _OperandT) -> H special

Shorthand for operator.__sub__(self.h(), other). See the h method.

Source code in dyce/h.py
def __sub__(self: HAbleT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python operator.__sub__(self.h(), other)``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __sub__(self.h(), other)

__truediv__(self: HAbleT, other: _OperandT) -> H special

Shorthand for operator.__truediv__(self.h(), other). See the h method.

Source code in dyce/h.py
def __truediv__(self: HAbleT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python operator.__truediv__(self.h(), other)``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __truediv__(self.h(), other)

__xor__(self: HAbleT, other: Union[IntT, H, HAbleT]) -> H special

Shorthand for operator.__xor__(self.h(), other). See the h method.

Source code in dyce/h.py
def __xor__(self: HAbleT, other: Union[IntT, H, HAbleT]) -> H:
    r"""
    Shorthand for ``#!python operator.__xor__(self.h(), other)``. See the
    [``h`` method][dyce.h.HAbleT.h].
    """
    return __xor__(self.h(), other)

eq(self: HAbleT, other: _OperandT) -> H

Shorthand for self.h().eq(other). See the h method and H.eq.

Source code in dyce/h.py
def eq(self: HAbleT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python self.h().eq(other)``. See the
    [``h`` method][dyce.h.HAbleT.h] and [``H.eq``][dyce.h.H.eq].
    """
    return self.h().eq(other)

even(self: HAbleT) -> H

Deprecated

This method is deprecated and will likely be removed in the next major release.

Shorthand for self.h().is_even(). See the h method and H.is_even.

Source code in dyce/h.py
@deprecated
def even(self: HAbleT) -> H:
    r"""
    !!! warning "Deprecated"

        This method is deprecated and will likely be removed in the next major
        release.

    Shorthand for ``#!python self.h().is_even()``. See the
    [``h`` method][dyce.h.HAbleT.h] and [``H.is_even``][dyce.h.H.is_even].
    """
    return self.h().is_even()

explode(self: HAbleT, max_depth: IntT = 1) -> H

Shorthand for self.h().explode(max_depth). See the h method and H.explode.

Source code in dyce/h.py
def explode(self: HAbleT, max_depth: IntT = 1) -> H:
    r"""
    Shorthand for ``#!python self.h().explode(max_depth)``. See the
    [``h`` method][dyce.h.HAbleT.h] and [``H.explode``][dyce.h.H.explode].
    """
    return self.h().explode(max_depth)

ge(self: HAbleT, other: _OperandT) -> H

Shorthand for self.h().ge(other). See the h method and H.ge.

Source code in dyce/h.py
def ge(self: HAbleT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python self.h().ge(other)``. See the
    [``h`` method][dyce.h.HAbleT.h] and [``H.ge``][dyce.h.H.ge].
    """
    return self.h().ge(other)

gt(self: HAbleT, other: _OperandT) -> H

Shorthand for self.h().gt(other). See the h method and H.gt.

Source code in dyce/h.py
def gt(self: HAbleT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python self.h().gt(other)``. See the
    [``h`` method][dyce.h.HAbleT.h] and [``H.gt``][dyce.h.H.gt].
    """
    return self.h().gt(other)

is_even(self: HAbleT) -> H

Shorthand for self.h().is_even(). See the h method and H.is_even.

Source code in dyce/h.py
def is_even(self: HAbleT) -> H:
    r"""
    Shorthand for ``#!python self.h().is_even()``. See the
    [``h`` method][dyce.h.HAbleT.h] and [``H.is_even``][dyce.h.H.is_even].
    """
    return self.h().is_even()

is_odd(self: HAbleT) -> H

Shorthand for self.h().is_odd(). See the h method and H.is_odd.

Source code in dyce/h.py
def is_odd(self: HAbleT) -> H:
    r"""
    Shorthand for ``#!python self.h().is_odd()``. See the
    [``h`` method][dyce.h.HAbleT.h] and [``H.is_odd``][dyce.h.H.is_odd].
    """
    return self.h().is_odd()

le(self: HAbleT, other: _OperandT) -> H

Shorthand for self.h().le(other). See the h method and H.le.

Source code in dyce/h.py
def le(self: HAbleT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python self.h().le(other)``. See the
    [``h`` method][dyce.h.HAbleT.h] and [``H.le``][dyce.h.H.le].
    """
    return self.h().le(other)

lt(self: HAbleT, other: _OperandT) -> H

Shorthand for self.h().lt(other). See the h method and H.lt.

Source code in dyce/h.py
def lt(self: HAbleT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python self.h().lt(other)``. See the
    [``h`` method][dyce.h.HAbleT.h] and [``H.lt``][dyce.h.H.lt].
    """
    return self.h().lt(other)

ne(self: HAbleT, other: _OperandT) -> H

Shorthand for self.h().ne(other). See the h method and H.ne.

Source code in dyce/h.py
def ne(self: HAbleT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python self.h().ne(other)``. See the
    [``h`` method][dyce.h.HAbleT.h] and [``H.ne``][dyce.h.H.ne].
    """
    return self.h().ne(other)

odd(self: HAbleT) -> H

Deprecated

This method is deprecated and will likely be removed in the next major release.

Shorthand for self.h().is_odd(). See the h method and H.is_odd.

Source code in dyce/h.py
@deprecated
def odd(self: HAbleT) -> H:
    r"""
    !!! warning "Deprecated"

        This method is deprecated and will likely be removed in the next major
        release.

    Shorthand for ``#!python self.h().is_odd()``. See the
    [``h`` method][dyce.h.HAbleT.h] and [``H.is_odd``][dyce.h.H.is_odd].
    """
    return self.h().is_odd()

substitute(self: HAbleT, expand: _ExpandT, coalesce: _CoalesceT = <function coalesce_replace at 0x10c5bda60>, max_depth: IntT = 1) -> H

Shorthand for self.h().substitute(expand, coalesce, max_depth). See the h method and H.substitute.

Source code in dyce/h.py
def substitute(
    self: HAbleT,
    expand: _ExpandT,
    coalesce: _CoalesceT = coalesce_replace,
    max_depth: IntT = 1,
) -> H:
    r"""
    Shorthand for ``#!python self.h().substitute(expand, coalesce, max_depth)``. See the
    [``h`` method][dyce.h.HAbleT.h] and [``H.substitute``][dyce.h.H.substitute].
    """
    return self.h().substitute(expand, coalesce, max_depth)

within(self: HAbleT, lo: OutcomeT, hi: OutcomeT, other: _OperandT = 0) -> H

Shorthand for self.h().within(lo, hi, other). See the h method and H.within.

Source code in dyce/h.py
def within(self: HAbleT, lo: OutcomeT, hi: OutcomeT, other: _OperandT = 0) -> H:
    r"""
    Shorthand for ``#!python self.h().within(lo, hi, other)``. See the
    [``h`` method][dyce.h.HAbleT.h] and [``H.within``][dyce.h.H.within].
    """
    return self.h().within(lo, hi, other)

HAbleT

A protocol whose implementer can be expressed as (or reduced to) an H object by calling its h method. Currently, only the P class implements this protocol, but this affords an integration point for dyce users.

__init__(self, *args, **kwargs) special

Source code in dyce/h.py
def _no_init(self, *args, **kwargs):
    if type(self)._is_protocol:
        raise TypeError('Protocols cannot be instantiated')

__subclasshook__(other) special

Source code in dyce/h.py
def _proto_hook(other):
    if not cls.__dict__.get('_is_protocol', False):
        return NotImplemented

    # First, perform various sanity checks.
    if not getattr(cls, '_is_runtime_protocol', False):
        if _allow_reckless_class_cheks():
            return NotImplemented
        raise TypeError("Instance and class checks can only be used with"
                        " @runtime_checkable protocols")
    if not _is_callable_members_only(cls):
        if _allow_reckless_class_cheks():
            return NotImplemented
        raise TypeError("Protocols with non-method members"
                        " don't support issubclass()")
    if not isinstance(other, type):
        # Same error message as for issubclass(1, int).
        raise TypeError('issubclass() arg 1 must be a class')

    # Second, perform the actual structural compatibility check.
    for attr in _get_protocol_attrs(cls):
        for base in other.__mro__:
            # Check if the members appears in the class dictionary...
            if attr in base.__dict__:
                if base.__dict__[attr] is None:
                    return NotImplemented
                break

            # ...or in annotations, if it is a sub-protocol.
            annotations = getattr(base, '__annotations__', {})
            if (isinstance(annotations, collections.abc.Mapping) and
                    attr in annotations and
                    issubclass(other, Generic) and other._is_protocol):
                break
        else:
            return NotImplemented
    return True

h(self) -> H

Express its implementer as an H object.

Source code in dyce/h.py
def h(self) -> H:
    r"""
    Express its implementer as an [``H`` object][dyce.h.H].
    """
    ...

coalesce_replace(h: H, outcome: OutcomeT) -> H

Default behavior for H.substitute. Returns h unmodified (outcome is ignored).

Source code in dyce/h.py
def coalesce_replace(h: H, outcome: OutcomeT) -> H:
    r"""
    Default behavior for [``H.substitute``][dyce.h.H.substitute]. Returns *h* unmodified
    (*outcome* is ignored).
    """
    return h