From 8ef5917d2cb74981f7617504c5a0248242c0dfe3 Mon Sep 17 00:00:00 2001 From: Matt Bogosian Date: Fri, 4 Aug 2023 07:44:08 -0500 Subject: [PATCH] Remove from __future__ import annotations Cf. beartype/numerary#19 --- docs/assets/graph.py | 2 - docs/assets/graph_classes_dyce_r.py | 2 - docs/assets/graph_filter.py | 2 - docs/assets/graph_rollin_expr.py | 2 - docs/assets/graph_rollin_pool.py | 2 - docs/assets/graph_rollin_select_1.py | 2 - docs/assets/graph_rollin_select_2.py | 2 - docs/assets/graph_rollin_value.py | 2 - docs/assets/graph_substitute_append.py | 2 - docs/assets/graph_substitute_replace.py | 2 - docs/assets/plot.py | 2 - docs/assets/plot_2d6_lo_hi.py | 2 - docs/assets/plot_4d6_variants.py | 2 - docs/assets/plot_advantage.py | 2 - docs/assets/plot_burning_arch.py | 2 - docs/assets/plot_d10_explode.py | 2 - docs/assets/plot_dupes.py | 2 - docs/assets/plot_great_weapon_fighting.py | 2 - docs/assets/plot_histogram.py | 2 - docs/assets/plot_ironsworn.py | 2 - docs/assets/plot_risus_first_round.py | 2 - docs/assets/plot_roll_and_keep.py | 2 - docs/assets/plug.py | 2 - docs/find_seed.py | 2 - dyce/__init__.py | 2 - dyce/evaluation.py | 2 - dyce/h.py | 129 ++++++------- dyce/lifecycle.py | 2 - dyce/p.py | 14 +- dyce/r.py | 210 +++++++++++----------- dyce/rng.py | 2 - dyce/types.py | 2 - helpers/mypy-doctests.py | 2 - tests/test_evaluation.py | 2 - tests/test_h.py | 2 - tests/test_p.py | 2 - tests/test_r.py | 2 - tests/test_rng.py | 2 - tests/test_types.py | 2 - 39 files changed, 176 insertions(+), 249 deletions(-) diff --git a/docs/assets/graph.py b/docs/assets/graph.py index 174a3281..d5c8aa26 100644 --- a/docs/assets/graph.py +++ b/docs/assets/graph.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import argparse import html import logging diff --git a/docs/assets/graph_classes_dyce_r.py b/docs/assets/graph_classes_dyce_r.py index 0a2e4237..654fe782 100644 --- a/docs/assets/graph_classes_dyce_r.py +++ b/docs/assets/graph_classes_dyce_r.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import logging import os import subprocess diff --git a/docs/assets/graph_filter.py b/docs/assets/graph_filter.py index db13a01a..a6969bae 100644 --- a/docs/assets/graph_filter.py +++ b/docs/assets/graph_filter.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from graph import COLORS, Dot, digraph, graphviz_walk from dyce.r import R diff --git a/docs/assets/graph_rollin_expr.py b/docs/assets/graph_rollin_expr.py index 7f987319..99af4c54 100644 --- a/docs/assets/graph_rollin_expr.py +++ b/docs/assets/graph_rollin_expr.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import random from graph import COLORS, Dot, digraph, graphviz_walk diff --git a/docs/assets/graph_rollin_pool.py b/docs/assets/graph_rollin_pool.py index b3ce9dd4..e46ac3bc 100644 --- a/docs/assets/graph_rollin_pool.py +++ b/docs/assets/graph_rollin_pool.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import random from graph import COLORS, Dot, digraph, graphviz_walk diff --git a/docs/assets/graph_rollin_select_1.py b/docs/assets/graph_rollin_select_1.py index 2e86fd51..651abfc5 100644 --- a/docs/assets/graph_rollin_select_1.py +++ b/docs/assets/graph_rollin_select_1.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import random from graph import COLORS, Dot, digraph, graphviz_walk diff --git a/docs/assets/graph_rollin_select_2.py b/docs/assets/graph_rollin_select_2.py index 9a97a681..f6456a8b 100644 --- a/docs/assets/graph_rollin_select_2.py +++ b/docs/assets/graph_rollin_select_2.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import random from graph import COLORS, Dot, digraph, graphviz_walk diff --git a/docs/assets/graph_rollin_value.py b/docs/assets/graph_rollin_value.py index 089e99c9..f867568f 100644 --- a/docs/assets/graph_rollin_value.py +++ b/docs/assets/graph_rollin_value.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from graph import Dot, digraph, graphviz_walk from dyce.r import ValueRoller diff --git a/docs/assets/graph_substitute_append.py b/docs/assets/graph_substitute_append.py index 2894c2fc..ae4ae376 100644 --- a/docs/assets/graph_substitute_append.py +++ b/docs/assets/graph_substitute_append.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import random from graph import COLORS, Dot, digraph, graphviz_walk diff --git a/docs/assets/graph_substitute_replace.py b/docs/assets/graph_substitute_replace.py index 5b71b5d0..b0a594cf 100644 --- a/docs/assets/graph_substitute_replace.py +++ b/docs/assets/graph_substitute_replace.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import random from graph import COLORS, Dot, digraph, graphviz_walk diff --git a/docs/assets/plot.py b/docs/assets/plot.py index 398d6cd3..737f3c66 100644 --- a/docs/assets/plot.py +++ b/docs/assets/plot.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import argparse import logging from functools import partial diff --git a/docs/assets/plot_2d6_lo_hi.py b/docs/assets/plot_2d6_lo_hi.py index 79ad9074..3dcc83bc 100644 --- a/docs/assets/plot_2d6_lo_hi.py +++ b/docs/assets/plot_2d6_lo_hi.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from anydyce.viz import plot_bar from dyce import H, P diff --git a/docs/assets/plot_4d6_variants.py b/docs/assets/plot_4d6_variants.py index bbbc1dae..1315524a 100644 --- a/docs/assets/plot_4d6_variants.py +++ b/docs/assets/plot_4d6_variants.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from anydyce.viz import plot_line from dyce import H, P diff --git a/docs/assets/plot_advantage.py b/docs/assets/plot_advantage.py index 4601ae60..1f365c45 100644 --- a/docs/assets/plot_advantage.py +++ b/docs/assets/plot_advantage.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from anydyce.viz import plot_line from dyce import H, P diff --git a/docs/assets/plot_burning_arch.py b/docs/assets/plot_burning_arch.py index b518155a..be4536f4 100644 --- a/docs/assets/plot_burning_arch.py +++ b/docs/assets/plot_burning_arch.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from anydyce.viz import plot_line from dyce import H diff --git a/docs/assets/plot_d10_explode.py b/docs/assets/plot_d10_explode.py index 48a1ac24..7676a4fc 100644 --- a/docs/assets/plot_d10_explode.py +++ b/docs/assets/plot_d10_explode.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from anydyce.viz import plot_line from dyce import H, P diff --git a/docs/assets/plot_dupes.py b/docs/assets/plot_dupes.py index 6a4f5054..9172851a 100644 --- a/docs/assets/plot_dupes.py +++ b/docs/assets/plot_dupes.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from anydyce.viz import plot_scatter from dyce import P diff --git a/docs/assets/plot_great_weapon_fighting.py b/docs/assets/plot_great_weapon_fighting.py index 910cfd52..476b53fd 100644 --- a/docs/assets/plot_great_weapon_fighting.py +++ b/docs/assets/plot_great_weapon_fighting.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from anydyce.viz import plot_burst, plot_line from dyce import H diff --git a/docs/assets/plot_histogram.py b/docs/assets/plot_histogram.py index 2144e46e..14cef864 100644 --- a/docs/assets/plot_histogram.py +++ b/docs/assets/plot_histogram.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from anydyce.viz import plot_bar from dyce import H diff --git a/docs/assets/plot_ironsworn.py b/docs/assets/plot_ironsworn.py index 3e9c81fc..79da7785 100644 --- a/docs/assets/plot_ironsworn.py +++ b/docs/assets/plot_ironsworn.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from enum import IntEnum, auto from functools import partial diff --git a/docs/assets/plot_risus_first_round.py b/docs/assets/plot_risus_first_round.py index e5cf2ab0..708dd914 100644 --- a/docs/assets/plot_risus_first_round.py +++ b/docs/assets/plot_risus_first_round.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from dyce import H diff --git a/docs/assets/plot_roll_and_keep.py b/docs/assets/plot_roll_and_keep.py index 484ada8c..800dde9c 100644 --- a/docs/assets/plot_roll_and_keep.py +++ b/docs/assets/plot_roll_and_keep.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from typing import Iterator from anydyce.viz import plot_line diff --git a/docs/assets/plug.py b/docs/assets/plug.py index bbd680fb..6bc3da4d 100644 --- a/docs/assets/plug.py +++ b/docs/assets/plug.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import argparse import importlib.machinery import importlib.util diff --git a/docs/find_seed.py b/docs/find_seed.py index e4df45f5..0b84f83c 100755 --- a/docs/find_seed.py +++ b/docs/find_seed.py @@ -7,8 +7,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import argparse import logging import random diff --git a/dyce/__init__.py b/dyce/__init__.py index b6a0a1fe..1e654b06 100644 --- a/dyce/__init__.py +++ b/dyce/__init__.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from typing import Union from .evaluation import * # noqa: F401,F403 diff --git a/dyce/evaluation.py b/dyce/evaluation.py index 7eed61cb..a36e5ae5 100644 --- a/dyce/evaluation.py +++ b/dyce/evaluation.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import sys from contextvars import ContextVar from fractions import Fraction diff --git a/dyce/h.py b/dyce/h.py index 5cd3a5e3..a8a644bf 100644 --- a/dyce/h.py +++ b/dyce/h.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import os import warnings from abc import abstractmethod @@ -106,7 +104,7 @@ @deprecated -def coalesce_replace(h: H, outcome: RealLike) -> H: +def coalesce_replace(h: "H", outcome: RealLike) -> "H": r""" !!! warning "Deprecated" @@ -512,49 +510,49 @@ def __contains__(self, key: RealLike) -> bool: # type: ignore [override] return key in self._h @beartype - def __add__(self, other: _OperandT) -> H: + def __add__(self, other: _OperandT) -> "H": try: return self.map(__add__, other) except NotImplementedError: return NotImplemented @beartype - def __radd__(self, other: RealLike) -> H: + def __radd__(self, other: RealLike) -> "H": try: return self.rmap(other, __add__) except NotImplementedError: return NotImplemented @beartype - def __sub__(self, other: _OperandT) -> H: + def __sub__(self, other: _OperandT) -> "H": try: return self.map(__sub__, other) except NotImplementedError: return NotImplemented @beartype - def __rsub__(self, other: RealLike) -> H: + def __rsub__(self, other: RealLike) -> "H": try: return self.rmap(other, __sub__) except NotImplementedError: return NotImplemented @beartype - def __mul__(self, other: _OperandT) -> H: + def __mul__(self, other: _OperandT) -> "H": try: return self.map(__mul__, other) except NotImplementedError: return NotImplemented @beartype - def __rmul__(self, other: RealLike) -> H: + def __rmul__(self, other: RealLike) -> "H": try: return self.rmap(other, __mul__) except NotImplementedError: return NotImplemented @beartype - def __matmul__(self, other: SupportsInt) -> H: + def __matmul__(self, other: SupportsInt) -> "H": try: other = as_int(other) except TypeError: @@ -566,60 +564,60 @@ def __matmul__(self, other: SupportsInt) -> H: return sum_h(repeat(self, other)) @beartype - def __rmatmul__(self, other: SupportsInt) -> H: + def __rmatmul__(self, other: SupportsInt) -> "H": return self.__matmul__(other) @beartype - def __truediv__(self, other: _OperandT) -> H: + def __truediv__(self, other: _OperandT) -> "H": try: return self.map(__truediv__, other) except NotImplementedError: return NotImplemented @beartype - def __rtruediv__(self, other: RealLike) -> H: + def __rtruediv__(self, other: RealLike) -> "H": try: return self.rmap(other, __truediv__) except NotImplementedError: return NotImplemented @beartype - def __floordiv__(self, other: _OperandT) -> H: + def __floordiv__(self, other: _OperandT) -> "H": try: return self.map(__floordiv__, other) except NotImplementedError: return NotImplemented @beartype - def __rfloordiv__(self, other: RealLike) -> H: + def __rfloordiv__(self, other: RealLike) -> "H": try: return self.rmap(other, __floordiv__) except NotImplementedError: return NotImplemented @beartype - def __mod__(self, other: _OperandT) -> H: + def __mod__(self, other: _OperandT) -> "H": try: return self.map(__mod__, other) except NotImplementedError: return NotImplemented @beartype - def __rmod__(self, other: RealLike) -> H: + def __rmod__(self, other: RealLike) -> "H": try: return self.rmap(other, __mod__) except NotImplementedError: return NotImplemented @beartype - def __pow__(self, other: _OperandT) -> H: + def __pow__(self, other: _OperandT) -> "H": try: return self.map(__pow__, other) except NotImplementedError: return NotImplemented @beartype - def __rpow__(self, other: RealLike) -> H: + def __rpow__(self, other: RealLike) -> "H": try: return self.rmap(other, __pow__) except NotImplementedError: @@ -627,7 +625,7 @@ def __rpow__(self, other: RealLike) -> H: @beartype # TODO(posita): See - def __and__(self, other: Union[SupportsInt, "H", "HableT"]) -> H: + def __and__(self, other: Union[SupportsInt, "H", "HableT"]) -> "H": try: if isinstance(other, SupportsInt): other = as_int(other) @@ -637,7 +635,7 @@ def __and__(self, other: Union[SupportsInt, "H", "HableT"]) -> H: return NotImplemented @beartype - def __rand__(self, other: SupportsInt) -> H: + def __rand__(self, other: SupportsInt) -> "H": try: return self.rmap(as_int(other), __and__) except (NotImplementedError, TypeError): @@ -645,7 +643,7 @@ def __rand__(self, other: SupportsInt) -> H: @beartype # TODO(posita): See - def __xor__(self, other: Union[SupportsInt, "H", "HableT"]) -> H: + def __xor__(self, other: Union[SupportsInt, "H", "HableT"]) -> "H": try: if isinstance(other, SupportsInt): other = as_int(other) @@ -655,7 +653,7 @@ def __xor__(self, other: Union[SupportsInt, "H", "HableT"]) -> H: return NotImplemented @beartype - def __rxor__(self, other: SupportsInt) -> H: + def __rxor__(self, other: SupportsInt) -> "H": try: return self.rmap(as_int(other), __xor__) except (NotImplementedError, TypeError): @@ -663,7 +661,7 @@ def __rxor__(self, other: SupportsInt) -> H: @beartype # TODO(posita): See - def __or__(self, other: Union[SupportsInt, "H", "HableT"]) -> H: + def __or__(self, other: Union[SupportsInt, "H", "HableT"]) -> "H": try: if isinstance(other, SupportsInt): other = as_int(other) @@ -673,26 +671,26 @@ def __or__(self, other: Union[SupportsInt, "H", "HableT"]) -> H: return NotImplemented @beartype - def __ror__(self, other: SupportsInt) -> H: + def __ror__(self, other: SupportsInt) -> "H": try: return self.rmap(as_int(other), __or__) except (NotImplementedError, TypeError): return NotImplemented @beartype - def __neg__(self) -> H: + def __neg__(self) -> "H": return self.umap(__neg__) @beartype - def __pos__(self) -> H: + def __pos__(self) -> "H": return self.umap(__pos__) @beartype - def __abs__(self) -> H: + def __abs__(self) -> "H": return self.umap(__abs__) @beartype - def __invert__(self) -> H: + def __invert__(self) -> "H": return self.umap(__invert__) @beartype @@ -748,7 +746,7 @@ def foreach( cls, dependent_term: Callable[..., HOrOutcomeT], **independent_sources: _SourceT, - ) -> H: + ) -> "H": r""" !!! warning "Deprecated" @@ -816,7 +814,7 @@ def _dependent_term(**roll_kw): return P.foreach(_dependent_term, **independent_sources) @beartype - def map(self, bin_op: _BinaryOperatorT, right_operand: _OperandT) -> H: + def map(self, bin_op: _BinaryOperatorT, right_operand: _OperandT) -> "H": r""" Applies *bin_op* to each outcome of the histogram as the left operand and *right_operand* as the right. Shorthands exist for many arithmetic operators and @@ -863,7 +861,7 @@ def map(self, bin_op: _BinaryOperatorT, right_operand: _OperandT) -> H: ) @beartype - def rmap(self, left_operand: RealLike, bin_op: _BinaryOperatorT) -> H: + def rmap(self, left_operand: RealLike, bin_op: _BinaryOperatorT) -> "H": r""" Analogous to the [``map`` method][dyce.h.H.map], but where the caller supplies *left_operand*. @@ -889,7 +887,7 @@ def rmap(self, left_operand: RealLike, bin_op: _BinaryOperatorT) -> H: ) @beartype - def umap(self, un_op: _UnaryOperatorT) -> H: + def umap(self, un_op: _UnaryOperatorT) -> "H": r""" Applies *un_op* to each outcome of the histogram. @@ -909,7 +907,7 @@ def umap(self, un_op: _UnaryOperatorT) -> H: return type(self)((un_op(outcome), count) for outcome, count in self.items()) @beartype - def lt(self, other: _OperandT) -> H: + def lt(self, other: _OperandT) -> "H": r""" Shorthand for ``#!python self.map(operator.__lt__, other).umap(bool)``. @@ -924,7 +922,7 @@ def lt(self, other: _OperandT) -> H: return self.map(__lt__, other).umap(bool) @beartype - def le(self, other: _OperandT) -> H: + def le(self, other: _OperandT) -> "H": r""" Shorthand for ``#!python self.map(operator.__le__, other).umap(bool)``. @@ -939,7 +937,7 @@ def le(self, other: _OperandT) -> H: return self.map(__le__, other).umap(bool) @beartype - def eq(self, other: _OperandT) -> H: + def eq(self, other: _OperandT) -> "H": r""" Shorthand for ``#!python self.map(operator.__eq__, other).umap(bool)``. @@ -954,7 +952,7 @@ def eq(self, other: _OperandT) -> H: return self.map(__eq__, other).umap(bool) @beartype - def ne(self, other: _OperandT) -> H: + def ne(self, other: _OperandT) -> "H": r""" Shorthand for ``#!python self.map(operator.__ne__, other).umap(bool)``. @@ -969,7 +967,7 @@ def ne(self, other: _OperandT) -> H: return self.map(__ne__, other).umap(bool) @beartype - def gt(self, other: _OperandT) -> H: + def gt(self, other: _OperandT) -> "H": r""" Shorthand for ``#!python self.map(operator.__gt__, other).umap(bool)``. @@ -984,7 +982,7 @@ def gt(self, other: _OperandT) -> H: return self.map(__gt__, other).umap(bool) @beartype - def ge(self, other: _OperandT) -> H: + def ge(self, other: _OperandT) -> "H": r""" Shorthand for ``#!python self.map(operator.__ge__, other).umap(bool)``. @@ -999,7 +997,7 @@ def ge(self, other: _OperandT) -> H: return self.map(__ge__, other).umap(bool) @beartype - def is_even(self) -> H: + def is_even(self) -> "H": r""" Equivalent to ``#!python self.umap(dyce.types.is_even)``. @@ -1014,7 +1012,7 @@ def is_even(self) -> H: return self.umap(is_even) @beartype - def is_odd(self) -> H: + def is_odd(self) -> "H": r""" Equivalent to ``#!python self.umap(dyce.types.is_odd)``. @@ -1029,7 +1027,7 @@ def is_odd(self) -> H: return self.umap(is_odd) @beartype - def accumulate(self, other: _SourceT) -> H: + def accumulate(self, other: _SourceT) -> "H": r""" Accumulates counts. @@ -1084,7 +1082,7 @@ def explode( self, max_depth: IntegralLike, precision_limit: None = None, - ) -> H: + ) -> "H": ... @overload @@ -1092,7 +1090,7 @@ def explode( self, max_depth: None, precision_limit: Union[RationalLikeMixedU, RealLike], - ) -> H: + ) -> "H": ... @overload @@ -1101,7 +1099,7 @@ def explode( max_depth: None = None, *, precision_limit: Union[RationalLikeMixedU, RealLike], - ) -> H: + ) -> "H": ... @overload @@ -1109,7 +1107,7 @@ def explode( self, max_depth: None = None, precision_limit: None = None, - ) -> H: + ) -> "H": ... @deprecated @@ -1118,7 +1116,7 @@ def explode( self, max_depth: Optional[IntegralLike] = None, precision_limit: Optional[Union[RationalLikeMixedU, RealLike]] = None, - ) -> H: + ) -> "H": r""" !!! warning "Deprecated" @@ -1154,7 +1152,7 @@ def _explode(h: H, outcome: RealLike) -> HOrOutcomeT: return self.substitute(_explode, __add__) @beartype - def lowest_terms(self) -> H: + def lowest_terms(self) -> "H": r""" Computes and returns a histogram whose nonzero counts share a greatest common divisor of 1. @@ -1182,7 +1180,7 @@ def lowest_terms(self) -> H: @experimental @beartype - def order_stat_for_n_at_pos(self, n: SupportsInt, pos: SupportsInt) -> H: + def order_stat_for_n_at_pos(self, n: SupportsInt, pos: SupportsInt) -> "H": r""" !!! warning "Experimental" @@ -1240,7 +1238,7 @@ def order_stat_for_n_at_pos(self, n: SupportsInt, pos: SupportsInt) -> H: return self._order_stat_funcs_by_n[n](pos) @beartype - def remove(self, outcome: RealLike) -> H: + def remove(self, outcome: RealLike) -> "H": if outcome not in self: return self @@ -1255,7 +1253,7 @@ def substitute( self, expand: _SubstituteExpandCallbackT, coalesce: _SubstituteCoalesceCallbackT = coalesce_replace, - ) -> H: + ) -> "H": ... @overload @@ -1266,7 +1264,7 @@ def substitute( *, max_depth: IntegralLike, precision_limit: None = None, - ) -> H: + ) -> "H": ... @overload @@ -1276,7 +1274,7 @@ def substitute( coalesce: _SubstituteCoalesceCallbackT, max_depth: IntegralLike, precision_limit: None = None, - ) -> H: + ) -> "H": ... @overload @@ -1287,7 +1285,7 @@ def substitute( *, max_depth: None, precision_limit: Union[RationalLikeMixedU, RealLike], - ) -> H: + ) -> "H": ... @overload @@ -1297,7 +1295,7 @@ def substitute( coalesce: _SubstituteCoalesceCallbackT, max_depth: None, precision_limit: Union[RationalLikeMixedU, RealLike], - ) -> H: + ) -> "H": ... @overload @@ -1308,7 +1306,7 @@ def substitute( max_depth: None = None, *, precision_limit: Union[RationalLikeMixedU, RealLike], - ) -> H: + ) -> "H": ... @overload @@ -1318,7 +1316,7 @@ def substitute( coalesce: _SubstituteCoalesceCallbackT = coalesce_replace, max_depth: None = None, precision_limit: None = None, - ) -> H: + ) -> "H": ... @deprecated @@ -1329,7 +1327,7 @@ def substitute( coalesce: _SubstituteCoalesceCallbackT = coalesce_replace, max_depth: Optional[IntegralLike] = None, precision_limit: Optional[Union[RationalLikeMixedU, RealLike]] = None, - ) -> H: + ) -> "H": r""" !!! warning "Deprecated" @@ -1384,7 +1382,7 @@ def _expand(result: HResult) -> HOrOutcomeT: return _expand(self, limit=limit) @beartype - def vs(self, other: _OperandT) -> H: + def vs(self, other: _OperandT) -> "H": r""" Compares the histogram with *other*. -1 represents where *other* is greater. 0 represents where they are equal. 1 represents where *other* is less. @@ -1404,7 +1402,7 @@ def vs(self, other: _OperandT) -> H: return self.within(0, 0, other) @beartype - def within(self, lo: RealLike, hi: RealLike, other: _OperandT = 0) -> H: + def within(self, lo: RealLike, hi: RealLike, other: _OperandT = 0) -> "H": r""" Computes the difference between the histogram and *other*. -1 represents where that difference is less than *lo*. 0 represents where that difference between *lo* @@ -1441,7 +1439,7 @@ def within(self, lo: RealLike, hi: RealLike, other: _OperandT = 0) -> H: return self.map(_within(lo, hi), other) @beartype - def zero_fill(self, outcomes: Iterable[RealLike]) -> H: + def zero_fill(self, outcomes: Iterable[RealLike]) -> "H": r""" Shorthand for ``#!python self.accumulate({outcome: 0 for outcome in outcomes})``. @@ -1637,6 +1635,11 @@ def format( >>> h = (2@H(6)).ge(7) >>> print(f"{' 65 chars wide -->|':->65}") ---------------------------------------------- 65 chars wide -->| + >>> print(H(1).format(scaled=False)) + avg | 1.00 + std | 0.00 + var | 0.00 + 1 | 100.00% |################################################## >>> print(h.format(scaled=False)) avg | 0.58 std | 0.49 @@ -1763,7 +1766,7 @@ def roll(self) -> RealLike: else 0 ) - def _order_stat_func_for_n(self, n: int) -> Callable[[int], H]: + def _order_stat_func_for_n(self, n: int) -> Callable[[int], "H"]: betas_by_outcome: dict[RealLike, tuple[H, H]] = {} for outcome in self.outcomes(): @@ -1780,7 +1783,7 @@ def _gen_h_items_at_pos(pos: int) -> Iterator[_OutcomeCountT]: ) @beartype - def order_stat_for_n_at_pos(pos: int) -> H: + def order_stat_for_n_at_pos(pos: int) -> "H": return type(self)(_gen_h_items_at_pos(pos)) return order_stat_for_n_at_pos diff --git a/dyce/lifecycle.py b/dyce/lifecycle.py index 3d5d46eb..26f2e852 100644 --- a/dyce/lifecycle.py +++ b/dyce/lifecycle.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import warnings from functools import wraps from typing import Any, Callable, Type, TypeVar, cast diff --git a/dyce/p.py b/dyce/p.py index 2dbbd2d6..09175b7d 100644 --- a/dyce/p.py +++ b/dyce/p.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from collections import Counter, defaultdict from fractions import Fraction from functools import wraps @@ -292,7 +290,7 @@ def __getitem__(self, key: SupportsIndex) -> H: ... @overload - def __getitem__(self, key: slice) -> P: + def __getitem__(self, key: slice) -> "P": ... @beartype @@ -307,7 +305,7 @@ def __iter__(self) -> Iterator[H]: return iter(self._hs) @beartype - def __matmul__(self, other: SupportsInt) -> P: + def __matmul__(self, other: SupportsInt) -> "P": try: other = as_int(other) except TypeError: @@ -319,7 +317,7 @@ def __matmul__(self, other: SupportsInt) -> P: return P(*chain.from_iterable(repeat(self, other))) @beartype - def __rmatmul__(self, other: SupportsInt) -> P: + def __rmatmul__(self, other: SupportsInt) -> "P": return self.__matmul__(other) @beartype @@ -925,7 +923,7 @@ def rolls_with_counts(self, *which: _GetItemT) -> Iterator[_RollCountT]: yield taken_outcomes, roll_count @beartype - def map(self, op: _BinaryOperatorT, right_operand: _OperandT) -> P: + def map(self, op: _BinaryOperatorT, right_operand: _OperandT) -> "P": r""" Shorthand for ``#!python P(*(h.map(op, right_operand) for h in self))``. See the [``H.map`` method][dyce.h.H.map]. @@ -941,7 +939,7 @@ def map(self, op: _BinaryOperatorT, right_operand: _OperandT) -> P: return P(*(h.map(op, right_operand) for h in self)) @beartype - def rmap(self, left_operand: RealLike, op: _BinaryOperatorT) -> P: + def rmap(self, left_operand: RealLike, op: _BinaryOperatorT) -> "P": r""" Shorthand for ``#!python P(*(h.rmap(left_operand, op) for h in self))``. See the [``H.rmap`` method][dyce.h.H.rmap]. @@ -958,7 +956,7 @@ def rmap(self, left_operand: RealLike, op: _BinaryOperatorT) -> P: return P(*(h.rmap(left_operand, op) for h in self)) @beartype - def umap(self, op: _UnaryOperatorT) -> P: + def umap(self, op: _UnaryOperatorT) -> "P": r""" Shorthand for ``#!python P(*(h.umap(op) for h in self))``. See the [``H.umap`` method][dyce.h.H.umap]. diff --git a/dyce/r.py b/dyce/r.py index 4a113926..6673ee7b 100644 --- a/dyce/r.py +++ b/dyce/r.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import enum import warnings from abc import abstractmethod @@ -313,49 +311,49 @@ def __ne__(self, other) -> bool: return super().__ne__(other) @beartype - def __add__(self, other: _ROperandT) -> BinarySumOpRoller: + def __add__(self, other: _ROperandT) -> "BinarySumOpRoller": try: return self.map(__add__, other) except NotImplementedError: return NotImplemented @beartype - def __radd__(self, other: RealLike) -> BinarySumOpRoller: + def __radd__(self, other: RealLike) -> "BinarySumOpRoller": try: return self.rmap(other, __add__) except NotImplementedError: return NotImplemented @beartype - def __sub__(self, other: _ROperandT) -> BinarySumOpRoller: + def __sub__(self, other: _ROperandT) -> "BinarySumOpRoller": try: return self.map(__sub__, other) except NotImplementedError: return NotImplemented @beartype - def __rsub__(self, other: RealLike) -> BinarySumOpRoller: + def __rsub__(self, other: RealLike) -> "BinarySumOpRoller": try: return self.rmap(other, __sub__) except NotImplementedError: return NotImplemented @beartype - def __mul__(self, other: _ROperandT) -> BinarySumOpRoller: + def __mul__(self, other: _ROperandT) -> "BinarySumOpRoller": try: return self.map(__mul__, other) except NotImplementedError: return NotImplemented @beartype - def __rmul__(self, other: RealLike) -> BinarySumOpRoller: + def __rmul__(self, other: RealLike) -> "BinarySumOpRoller": try: return self.rmap(other, __mul__) except NotImplementedError: return NotImplemented @beartype - def __matmul__(self, other: SupportsInt) -> R: + def __matmul__(self, other: SupportsInt) -> "R": try: other = as_int(other) except TypeError: @@ -367,67 +365,67 @@ def __matmul__(self, other: SupportsInt) -> R: return RepeatRoller(other, self) @beartype - def __rmatmul__(self, other: SupportsInt) -> R: + def __rmatmul__(self, other: SupportsInt) -> "R": return self.__matmul__(other) @beartype - def __truediv__(self, other: _ROperandT) -> BinarySumOpRoller: + def __truediv__(self, other: _ROperandT) -> "BinarySumOpRoller": try: return self.map(__truediv__, other) except NotImplementedError: return NotImplemented @beartype - def __rtruediv__(self, other: RealLike) -> BinarySumOpRoller: + def __rtruediv__(self, other: RealLike) -> "BinarySumOpRoller": try: return self.rmap(other, __truediv__) except NotImplementedError: return NotImplemented @beartype - def __floordiv__(self, other: _ROperandT) -> BinarySumOpRoller: + def __floordiv__(self, other: _ROperandT) -> "BinarySumOpRoller": try: return self.map(__floordiv__, other) except NotImplementedError: return NotImplemented @beartype - def __rfloordiv__(self, other: RealLike) -> BinarySumOpRoller: + def __rfloordiv__(self, other: RealLike) -> "BinarySumOpRoller": try: return self.rmap(other, __floordiv__) except NotImplementedError: return NotImplemented @beartype - def __mod__(self, other: _ROperandT) -> BinarySumOpRoller: + def __mod__(self, other: _ROperandT) -> "BinarySumOpRoller": try: return self.map(__mod__, other) except NotImplementedError: return NotImplemented @beartype - def __rmod__(self, other: RealLike) -> BinarySumOpRoller: + def __rmod__(self, other: RealLike) -> "BinarySumOpRoller": try: return self.rmap(other, __mod__) except NotImplementedError: return NotImplemented @beartype - def __pow__(self, other: _ROperandT) -> BinarySumOpRoller: + def __pow__(self, other: _ROperandT) -> "BinarySumOpRoller": try: return self.map(__pow__, other) except NotImplementedError: return NotImplemented @beartype - def __rpow__(self, other: RealLike) -> BinarySumOpRoller: + def __rpow__(self, other: RealLike) -> "BinarySumOpRoller": try: return self.rmap(other, __pow__) except NotImplementedError: return NotImplemented @beartype - def __and__(self, other: Union[_SourceT, SupportsInt]) -> BinarySumOpRoller: + def __and__(self, other: Union[_SourceT, SupportsInt]) -> "BinarySumOpRoller": try: if isinstance(other, R): return self.map(__and__, other) @@ -437,14 +435,14 @@ def __and__(self, other: Union[_SourceT, SupportsInt]) -> BinarySumOpRoller: return NotImplemented @beartype - def __rand__(self, other: SupportsInt) -> BinarySumOpRoller: + def __rand__(self, other: SupportsInt) -> "BinarySumOpRoller": try: return self.rmap(as_int(other), __and__) except NotImplementedError: return NotImplemented @beartype - def __xor__(self, other: Union[_SourceT, SupportsInt]) -> BinarySumOpRoller: + def __xor__(self, other: Union[_SourceT, SupportsInt]) -> "BinarySumOpRoller": try: if isinstance(other, R): return self.map(__xor__, other) @@ -454,14 +452,14 @@ def __xor__(self, other: Union[_SourceT, SupportsInt]) -> BinarySumOpRoller: return NotImplemented @beartype - def __rxor__(self, other: SupportsInt) -> BinarySumOpRoller: + def __rxor__(self, other: SupportsInt) -> "BinarySumOpRoller": try: return self.rmap(as_int(other), __xor__) except NotImplementedError: return NotImplemented @beartype - def __or__(self, other: Union[_SourceT, SupportsInt]) -> BinarySumOpRoller: + def __or__(self, other: Union[_SourceT, SupportsInt]) -> "BinarySumOpRoller": try: if isinstance(other, R): return self.map(__or__, other) @@ -471,30 +469,30 @@ def __or__(self, other: Union[_SourceT, SupportsInt]) -> BinarySumOpRoller: return NotImplemented @beartype - def __ror__(self, other: SupportsInt) -> BinarySumOpRoller: + def __ror__(self, other: SupportsInt) -> "BinarySumOpRoller": try: return self.rmap(as_int(other), __or__) except NotImplementedError: return NotImplemented @beartype - def __neg__(self) -> UnarySumOpRoller: + def __neg__(self) -> "UnarySumOpRoller": return self.umap(__neg__) @beartype - def __pos__(self) -> UnarySumOpRoller: + def __pos__(self) -> "UnarySumOpRoller": return self.umap(__pos__) @beartype - def __abs__(self) -> UnarySumOpRoller: + def __abs__(self) -> "UnarySumOpRoller": return self.umap(__abs__) @beartype - def __invert__(self) -> UnarySumOpRoller: + def __invert__(self) -> "UnarySumOpRoller": return self.umap(__invert__) @abstractmethod - def roll(self) -> Roll: + def roll(self) -> "Roll": r""" Sub-classes should implement this method to return a new [``Roll`` object][dyce.r.Roll] taking into account any @@ -638,7 +636,7 @@ def from_sources( cls, *sources: _SourceT, annotation: Any = "", - ) -> PoolRoller: + ) -> "PoolRoller": r""" Shorthand for ``#!python cls.from_sources_iterable(rs, annotation=annotation)``. @@ -652,7 +650,7 @@ def from_sources_iterable( cls, sources: Iterable[_SourceT], annotation: Any = "", - ) -> PoolRoller: + ) -> "PoolRoller": r""" Creates and returns a roller for “pooling” zero or more *sources*. @@ -700,7 +698,7 @@ def from_value( cls, value: _ValueT, annotation: Any = "", - ) -> ValueRoller: + ) -> "ValueRoller": r""" Creates and returns a [``ValueRoller``][dyce.r.ValueRoller] from *value*. @@ -730,7 +728,7 @@ def from_values( cls, *values: _ValueT, annotation: Any = "", - ) -> PoolRoller: + ) -> "PoolRoller": r""" Shorthand for ``#!python cls.from_values_iterable(values, annotation=annotation)``. @@ -744,7 +742,7 @@ def from_values_iterable( cls, values: Iterable[_ValueT], annotation: Any = "", - ) -> PoolRoller: + ) -> "PoolRoller": r""" Shorthand for ``#!python cls.from_sources_iterable((cls.from_value(value) for value in values), annotation=annotation)``. @@ -764,7 +762,7 @@ def filter_from_sources( predicate: _PredicateT, *sources: _SourceT, annotation: Any = "", - ) -> FilterRoller: + ) -> "FilterRoller": r""" Shorthand for ``#!python cls.filter_from_sources_iterable(predicate, sources, annotation=annotation)``. @@ -783,7 +781,7 @@ def filter_from_sources_iterable( predicate: _PredicateT, sources: Iterable[_SourceT], annotation: Any = "", - ) -> FilterRoller: + ) -> "FilterRoller": r""" Creates and returns a [``FilterRoller``][dyce.r.FilterRoller] for applying filterion *predicate* to sorted outcomes from *sources*. @@ -818,7 +816,7 @@ def filter_from_values( predicate: _PredicateT, *values: _ValueT, annotation: Any = "", - ) -> FilterRoller: + ) -> "FilterRoller": r""" Shorthand for ``#!python cls.filter_from_values_iterable(predicate, values, annotation=annotation)``. @@ -835,7 +833,7 @@ def filter_from_values_iterable( predicate: _PredicateT, values: Iterable[_ValueT], annotation: Any = "", - ) -> FilterRoller: + ) -> "FilterRoller": r""" Shorthand for ``#!python cls.filter_from_sources_iterable((cls.from_value(value) for value in values), annotation=annotation)``. @@ -857,7 +855,7 @@ def select_from_sources( which: Iterable[_GetItemT], *sources: _SourceT, annotation: Any = "", - ) -> SelectionRoller: + ) -> "SelectionRoller": r""" Shorthand for ``#!python cls.select_from_sources_iterable(which, sources, annotation=annotation)``. @@ -874,7 +872,7 @@ def select_from_sources_iterable( which: Iterable[_GetItemT], sources: Iterable[_SourceT], annotation: Any = "", - ) -> SelectionRoller: + ) -> "SelectionRoller": r""" Creates and returns a [``SelectionRoller``][dyce.r.SelectionRoller] for applying selection *which* to sorted outcomes from *sources*. @@ -909,7 +907,7 @@ def select_from_values( which: Iterable[_GetItemT], *values: _ValueT, annotation: Any = "", - ) -> SelectionRoller: + ) -> "SelectionRoller": r""" Shorthand for ``#!python cls.select_from_values_iterable(which, values, annotation=annotation)``. @@ -926,7 +924,7 @@ def select_from_values_iterable( which: Iterable[_GetItemT], values: Iterable[_ValueT], annotation: Any = "", - ) -> SelectionRoller: + ) -> "SelectionRoller": r""" Shorthand for ``#!python cls.select_from_sources_iterable((cls.from_value(value) for value in values), annotation=annotation)``. @@ -950,7 +948,7 @@ def source_rolls(self) -> Iterator["Roll"]: yield source.roll() @beartype - def annotate(self, annotation: Any = "") -> R: + def annotate(self, annotation: Any = "") -> "R": r""" Generates a copy of the roller with the desired annotation. @@ -973,7 +971,7 @@ def map( bin_op: _RollOutcomeBinaryOperatorT, right_operand: _ROperandT, annotation: Any = "", - ) -> BinarySumOpRoller: + ) -> "BinarySumOpRoller": r""" Creates and returns a [``BinarySumOpRoller``][dyce.r.BinarySumOpRoller] for applying *bin_op* to this roller and *right_operand* as its sources. Shorthands exist for @@ -1008,7 +1006,7 @@ def rmap( left_operand: Union[RealLike, "RollOutcome"], bin_op: _RollOutcomeBinaryOperatorT, annotation: Any = "", - ) -> BinarySumOpRoller: + ) -> "BinarySumOpRoller": r""" Analogous to the [``map`` method][dyce.r.R.map], but where the caller supplies *left_operand*. @@ -1047,7 +1045,7 @@ def umap( self, un_op: _RollOutcomeUnaryOperatorT, annotation: Any = "", - ) -> UnarySumOpRoller: + ) -> "UnarySumOpRoller": r""" Creates and returns a [``UnarySumOpRoller``][dyce.r.UnarySumOpRoller] roller for applying *un_op* to this roller as its source. @@ -1068,7 +1066,7 @@ def umap( return UnarySumOpRoller(un_op, self, annotation=annotation) @beartype - def lt(self, other: _ROperandT) -> BinarySumOpRoller: + def lt(self, other: _ROperandT) -> "BinarySumOpRoller": r""" Shorthand for ``#!python self.map(lambda left, right: left.lt(right), other)``. @@ -1081,7 +1079,7 @@ def _lt(left_operand: RollOutcome, right_operand: RollOutcome) -> RollOutcome: return self.map(_lt, other) @beartype - def le(self, other: _ROperandT) -> BinarySumOpRoller: + def le(self, other: _ROperandT) -> "BinarySumOpRoller": r""" Shorthand for ``#!python self.map(lambda left, right: left.le(right), other)``. @@ -1094,7 +1092,7 @@ def _le(left_operand: RollOutcome, right_operand: RollOutcome) -> RollOutcome: return self.map(_le, other) @beartype - def eq(self, other: _ROperandT) -> BinarySumOpRoller: + def eq(self, other: _ROperandT) -> "BinarySumOpRoller": r""" Shorthand for ``#!python self.map(lambda left, right: left.eq(right), other)``. @@ -1107,7 +1105,7 @@ def _eq(left_operand: RollOutcome, right_operand: RollOutcome) -> RollOutcome: return self.map(_eq, other) @beartype - def ne(self, other: _ROperandT) -> BinarySumOpRoller: + def ne(self, other: _ROperandT) -> "BinarySumOpRoller": r""" Shorthand for ``#!python self.map(lambda left, right: left.ne(right), other)``. @@ -1120,7 +1118,7 @@ def _ne(left_operand: RollOutcome, right_operand: RollOutcome) -> RollOutcome: return self.map(_ne, other) @beartype - def gt(self, other: _ROperandT) -> BinarySumOpRoller: + def gt(self, other: _ROperandT) -> "BinarySumOpRoller": r""" Shorthand for ``#!python self.map(lambda left, right: left.gt(right), other)``. @@ -1133,7 +1131,7 @@ def _gt(left_operand: RollOutcome, right_operand: RollOutcome) -> RollOutcome: return self.map(_gt, other) @beartype - def ge(self, other: _ROperandT) -> BinarySumOpRoller: + def ge(self, other: _ROperandT) -> "BinarySumOpRoller": r""" Shorthand for ``#!python self.map(lambda left, right: left.ge(right), other)``. @@ -1146,7 +1144,7 @@ def _ge(left_operand: RollOutcome, right_operand: RollOutcome) -> RollOutcome: return self.map(_ge, other) @beartype - def is_even(self) -> UnarySumOpRoller: + def is_even(self) -> "UnarySumOpRoller": r""" Shorthand for: ``#!python self.umap(lambda operand: operand.is_even())``. @@ -1159,7 +1157,7 @@ def _is_even(operand: RollOutcome) -> RollOutcome: return self.umap(_is_even) @beartype - def is_odd(self) -> UnarySumOpRoller: + def is_odd(self) -> "UnarySumOpRoller": r""" Shorthand for: ``#!python self.umap(lambda operand: operand.is_odd())``. @@ -1176,7 +1174,7 @@ def filter( self, predicate: _PredicateT, annotation: Any = "", - ) -> FilterRoller: + ) -> "FilterRoller": r""" Shorthand for ``#!python type(self).filter_from_sources(predicate, self, annotation=annotation)``. @@ -1190,7 +1188,7 @@ def select( self, *which: _GetItemT, annotation: Any = "", - ) -> SelectionRoller: + ) -> "SelectionRoller": r""" Shorthand for ``#!python self.select_iterable(which, annotation=annotation)``. @@ -1203,7 +1201,7 @@ def select_iterable( self, which: Iterable[_GetItemT], annotation: Any = "", - ) -> SelectionRoller: + ) -> "SelectionRoller": r""" Shorthand for ``#!python type(self).select_from_sources(which, self, annotation=annotation)``. @@ -1249,7 +1247,7 @@ def __repr__(self) -> str: return f"{type(self).__name__}(value={self.value!r}, annotation={self.annotation!r})" @beartype - def roll(self) -> Roll: + def roll(self) -> "Roll": r"""""" if isinstance(self.value, P): return Roll( @@ -1338,7 +1336,7 @@ class PoolRoller(R): # ---- Overrides ------------------------------------------------------------------- @beartype - def roll(self) -> Roll: + def roll(self) -> "Roll": r"""""" source_rolls = list(self.source_rolls()) @@ -1406,7 +1404,7 @@ def __eq__(self, other) -> bool: return super().__eq__(other) and self.n == other.n @beartype - def roll(self) -> Roll: + def roll(self) -> "Roll": r"""""" source_rolls: list[Roll] = [] @@ -1470,7 +1468,7 @@ def __eq__(self, other) -> bool: return super().__eq__(other) and (_callable_cmp(self.op, other.op)) @beartype - def roll(self) -> Roll: + def roll(self) -> "Roll": r"""""" source_rolls = list(self.source_rolls()) res = self.op( @@ -1509,7 +1507,7 @@ class NarySumOpRoller(BasicOpRoller): # ---- Overrides ------------------------------------------------------------------- @beartype - def roll(self) -> Roll: + def roll(self) -> "Roll": r"""""" source_rolls = list(self.source_rolls()) @@ -1775,7 +1773,7 @@ def __eq__(self, other) -> bool: return super().__eq__(other) and _callable_cmp(self.predicate, other.predicate) @beartype - def roll(self) -> Roll: + def roll(self) -> "Roll": r"""""" source_rolls = list(self.source_rolls()) @@ -1914,7 +1912,7 @@ def __eq__(self, other) -> bool: return super().__eq__(other) and self.which == other.which @beartype - def roll(self) -> Roll: + def roll(self) -> "Roll": r"""""" source_rolls = list(self.source_rolls()) roll_outcomes = list( @@ -2052,7 +2050,7 @@ def __eq__(self, other) -> bool: ) @beartype - def roll(self) -> Roll: + def roll(self) -> "Roll": r"""""" (source_roll,) = self.source_rolls() source_rolls: list[Roll] = [] @@ -2227,98 +2225,98 @@ def __ge__(self, other: _RollOutcomeOperandT) -> bool: return NotImplemented @beartype - def __add__(self, other: _RollOutcomeOperandT) -> RollOutcome: + def __add__(self, other: _RollOutcomeOperandT) -> "RollOutcome": try: return self.map(__add__, other) except NotImplementedError: return NotImplemented @beartype - def __radd__(self, other: RealLike) -> RollOutcome: + def __radd__(self, other: RealLike) -> "RollOutcome": try: return self.rmap(other, __add__) except NotImplementedError: return NotImplemented @beartype - def __sub__(self, other: _RollOutcomeOperandT) -> RollOutcome: + def __sub__(self, other: _RollOutcomeOperandT) -> "RollOutcome": try: return self.map(__sub__, other) except NotImplementedError: return NotImplemented @beartype - def __rsub__(self, other: RealLike) -> RollOutcome: + def __rsub__(self, other: RealLike) -> "RollOutcome": try: return self.rmap(other, __sub__) except NotImplementedError: return NotImplemented @beartype - def __mul__(self, other: _RollOutcomeOperandT) -> RollOutcome: + def __mul__(self, other: _RollOutcomeOperandT) -> "RollOutcome": try: return self.map(__mul__, other) except NotImplementedError: return NotImplemented @beartype - def __rmul__(self, other: RealLike) -> RollOutcome: + def __rmul__(self, other: RealLike) -> "RollOutcome": try: return self.rmap(other, __mul__) except NotImplementedError: return NotImplemented @beartype - def __truediv__(self, other: _RollOutcomeOperandT) -> RollOutcome: + def __truediv__(self, other: _RollOutcomeOperandT) -> "RollOutcome": try: return self.map(__truediv__, other) except NotImplementedError: return NotImplemented @beartype - def __rtruediv__(self, other: RealLike) -> RollOutcome: + def __rtruediv__(self, other: RealLike) -> "RollOutcome": try: return self.rmap(other, __truediv__) except NotImplementedError: return NotImplemented @beartype - def __floordiv__(self, other: _RollOutcomeOperandT) -> RollOutcome: + def __floordiv__(self, other: _RollOutcomeOperandT) -> "RollOutcome": try: return self.map(__floordiv__, other) except NotImplementedError: return NotImplemented @beartype - def __rfloordiv__(self, other: RealLike) -> RollOutcome: + def __rfloordiv__(self, other: RealLike) -> "RollOutcome": try: return self.rmap(other, __floordiv__) except NotImplementedError: return NotImplemented @beartype - def __mod__(self, other: _RollOutcomeOperandT) -> RollOutcome: + def __mod__(self, other: _RollOutcomeOperandT) -> "RollOutcome": try: return self.map(__mod__, other) except NotImplementedError: return NotImplemented @beartype - def __rmod__(self, other: RealLike) -> RollOutcome: + def __rmod__(self, other: RealLike) -> "RollOutcome": try: return self.rmap(other, __mod__) except NotImplementedError: return NotImplemented @beartype - def __pow__(self, other: _RollOutcomeOperandT) -> RollOutcome: + def __pow__(self, other: _RollOutcomeOperandT) -> "RollOutcome": try: return self.map(__pow__, other) except NotImplementedError: return NotImplemented @beartype - def __rpow__(self, other: RealLike) -> RollOutcome: + def __rpow__(self, other: RealLike) -> "RollOutcome": try: return self.rmap(other, __pow__) except NotImplementedError: @@ -2326,7 +2324,7 @@ def __rpow__(self, other: RealLike) -> RollOutcome: @beartype # TODO(posita): See - def __and__(self, other: Union["RollOutcome", SupportsInt]) -> RollOutcome: + def __and__(self, other: Union["RollOutcome", SupportsInt]) -> "RollOutcome": try: if isinstance(other, SupportsInt): other = as_int(other) @@ -2336,7 +2334,7 @@ def __and__(self, other: Union["RollOutcome", SupportsInt]) -> RollOutcome: return NotImplemented @beartype - def __rand__(self, other: SupportsInt) -> RollOutcome: + def __rand__(self, other: SupportsInt) -> "RollOutcome": try: return self.rmap(as_int(other), __and__) except (NotImplementedError, TypeError): @@ -2344,7 +2342,7 @@ def __rand__(self, other: SupportsInt) -> RollOutcome: @beartype # TODO(posita): See - def __xor__(self, other: Union["RollOutcome", SupportsInt]) -> RollOutcome: + def __xor__(self, other: Union["RollOutcome", SupportsInt]) -> "RollOutcome": try: if isinstance(other, SupportsInt): other = as_int(other) @@ -2354,7 +2352,7 @@ def __xor__(self, other: Union["RollOutcome", SupportsInt]) -> RollOutcome: return NotImplemented @beartype - def __rxor__(self, other: SupportsInt) -> RollOutcome: + def __rxor__(self, other: SupportsInt) -> "RollOutcome": try: return self.rmap(as_int(other), __xor__) except (NotImplementedError, TypeError): @@ -2362,7 +2360,7 @@ def __rxor__(self, other: SupportsInt) -> RollOutcome: @beartype # TODO(posita): See - def __or__(self, other: Union["RollOutcome", SupportsInt]) -> RollOutcome: + def __or__(self, other: Union["RollOutcome", SupportsInt]) -> "RollOutcome": try: if isinstance(other, SupportsInt): other = as_int(other) @@ -2372,26 +2370,26 @@ def __or__(self, other: Union["RollOutcome", SupportsInt]) -> RollOutcome: return NotImplemented @beartype - def __ror__(self, other: SupportsInt) -> RollOutcome: + def __ror__(self, other: SupportsInt) -> "RollOutcome": try: return self.rmap(as_int(other), __or__) except (NotImplementedError, TypeError): return NotImplemented @beartype - def __neg__(self) -> RollOutcome: + def __neg__(self) -> "RollOutcome": return self.umap(__neg__) @beartype - def __pos__(self) -> RollOutcome: + def __pos__(self) -> "RollOutcome": return self.umap(__pos__) @beartype - def __abs__(self) -> RollOutcome: + def __abs__(self) -> "RollOutcome": return self.umap(__abs__) @beartype - def __invert__(self) -> RollOutcome: + def __invert__(self) -> "RollOutcome": return self.umap(__invert__) # ---- Properties ------------------------------------------------------------------ @@ -2417,7 +2415,7 @@ def r(self) -> R: return self.source_roll.r @property - def source_roll(self) -> Roll: + def source_roll(self) -> "Roll": r""" Returns the roll if one has been associated with this roll outcome. Usually that happens by submitting the roll outcome to the @@ -2455,7 +2453,7 @@ def source_roll(self) -> Roll: return self._roll @property - def sources(self) -> tuple[RollOutcome, ...]: + def sources(self) -> tuple["RollOutcome", ...]: r""" The source roll outcomes from which this roll outcome was generated. """ @@ -2476,7 +2474,7 @@ def map( self, bin_op: _BinaryOperatorT, right_operand: _RollOutcomeOperandT, - ) -> RollOutcome: + ) -> "RollOutcome": r""" Applies *bin_op* to the value of this roll outcome as the left operand and *right_operand* as the right. Shorthands exist for many arithmetic operators and @@ -2513,7 +2511,7 @@ def map( raise NotImplementedError @beartype - def rmap(self, left_operand: RealLike, bin_op: _BinaryOperatorT) -> RollOutcome: + def rmap(self, left_operand: RealLike, bin_op: _BinaryOperatorT) -> "RollOutcome": r""" Analogous to the [``map`` method][dyce.r.RollOutcome.map], but where the caller supplies *left_operand*. @@ -2551,7 +2549,7 @@ def rmap(self, left_operand: RealLike, bin_op: _BinaryOperatorT) -> RollOutcome: def umap( self, un_op: _UnaryOperatorT, - ) -> RollOutcome: + ) -> "RollOutcome": r""" Applies *un_op* to the value of this roll outcome. Shorthands exist for many arithmetic operators and comparators. @@ -2577,7 +2575,7 @@ def umap( return type(self)(un_op(self.value), sources=(self,)) @beartype - def lt(self, other: _RollOutcomeOperandT) -> RollOutcome: + def lt(self, other: _RollOutcomeOperandT) -> "RollOutcome": if isinstance(other, RollOutcome): return type(self)(bool(__lt__(self, other)), sources=(self, other)) elif self.value is not None: @@ -2586,7 +2584,7 @@ def lt(self, other: _RollOutcomeOperandT) -> RollOutcome: raise ValueError(f"unable to compare {self} to {other}") @beartype - def le(self, other: _RollOutcomeOperandT) -> RollOutcome: + def le(self, other: _RollOutcomeOperandT) -> "RollOutcome": if isinstance(other, RollOutcome): return type(self)(bool(__le__(self, other)), sources=(self, other)) elif self.value is not None: @@ -2595,7 +2593,7 @@ def le(self, other: _RollOutcomeOperandT) -> RollOutcome: raise ValueError(f"unable to compare {self} to {other}") @beartype - def eq(self, other: _RollOutcomeOperandT) -> RollOutcome: + def eq(self, other: _RollOutcomeOperandT) -> "RollOutcome": if isinstance(other, RollOutcome): return type(self)(bool(__eq__(self, other)), sources=(self, other)) elif self.value is not None: @@ -2604,14 +2602,14 @@ def eq(self, other: _RollOutcomeOperandT) -> RollOutcome: raise ValueError(f"unable to compare {self} to {other}") @beartype - def ne(self, other: _RollOutcomeOperandT) -> RollOutcome: + def ne(self, other: _RollOutcomeOperandT) -> "RollOutcome": if isinstance(other, RollOutcome): return type(self)(bool(__ne__(self, other)), sources=(self, other)) else: return type(self)(bool(__ne__(self.value, other)), sources=(self,)) @beartype - def gt(self, other: _RollOutcomeOperandT) -> RollOutcome: + def gt(self, other: _RollOutcomeOperandT) -> "RollOutcome": if isinstance(other, RollOutcome): return type(self)(bool(__gt__(self, other)), sources=(self, other)) elif self.value is not None: @@ -2620,7 +2618,7 @@ def gt(self, other: _RollOutcomeOperandT) -> RollOutcome: raise ValueError(f"unable to compare {self} to {other}") @beartype - def ge(self, other: _RollOutcomeOperandT) -> RollOutcome: + def ge(self, other: _RollOutcomeOperandT) -> "RollOutcome": if isinstance(other, RollOutcome): return type(self)(bool(__ge__(self, other)), sources=(self, other)) elif self.value is not None: @@ -2629,7 +2627,7 @@ def ge(self, other: _RollOutcomeOperandT) -> RollOutcome: raise ValueError(f"unable to compare {self} to {other}") @beartype - def is_even(self) -> RollOutcome: + def is_even(self) -> "RollOutcome": r""" Shorthand for: ``#!python self.umap(dyce.types.is_even)``. @@ -2638,7 +2636,7 @@ def is_even(self) -> RollOutcome: return self.umap(is_even) @beartype - def is_odd(self) -> RollOutcome: + def is_odd(self) -> "RollOutcome": r""" Shorthand for: ``#!python self.umap(dyce.types.is_even)``. @@ -2651,7 +2649,7 @@ def adopt( self, sources: Iterable["RollOutcome"] = (), coalesce_mode: CoalesceMode = CoalesceMode.REPLACE, - ) -> RollOutcome: + ) -> "RollOutcome": r""" Creates and returns a new roll outcome identical to this roll outcome, but with *sources* replacing or appended to this roll outcome’s sources in accordance @@ -2709,7 +2707,7 @@ def adopt( return adopted_roll_outcome @beartype - def euthanize(self) -> RollOutcome: + def euthanize(self) -> "RollOutcome": r""" Shorthand for ``#!python self.umap(lambda operand: None)``. @@ -2872,7 +2870,7 @@ def r(self) -> R: return self._r @property - def source_rolls(self) -> tuple[Roll, ...]: + def source_rolls(self) -> tuple["Roll", ...]: r""" The source rolls from which this roll was generated. """ @@ -2885,7 +2883,7 @@ def adopt( self, sources: Iterable["RollOutcome"] = (), coalesce_mode: CoalesceMode = CoalesceMode.REPLACE, - ) -> Roll: + ) -> "Roll": r""" Shorthand for ``#!python Roll(self.r, (roll_outcome.adopt(sources, coalesce_mode) for roll_outcome in self), self.source_rolls)``. diff --git a/dyce/rng.py b/dyce/rng.py index 2086ad99..8780c839 100644 --- a/dyce/rng.py +++ b/dyce/rng.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from abc import ABC from random import Random from sys import version_info diff --git a/dyce/types.py b/dyce/types.py index e892af2b..f5c2fc38 100644 --- a/dyce/types.py +++ b/dyce/types.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import re from operator import __getitem__, __index__ from typing import Any, Callable, Iterable, Iterator, Sequence, TypeVar, Union diff --git a/helpers/mypy-doctests.py b/helpers/mypy-doctests.py index 80c48128..4186d398 100755 --- a/helpers/mypy-doctests.py +++ b/helpers/mypy-doctests.py @@ -7,8 +7,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import argparse import doctest import logging diff --git a/tests/test_evaluation.py b/tests/test_evaluation.py index 8575b3ef..e8251dd0 100644 --- a/tests/test_evaluation.py +++ b/tests/test_evaluation.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from collections import Counter from enum import IntEnum, auto diff --git a/tests/test_h.py b/tests/test_h.py index 16854808..666b2ce4 100644 --- a/tests/test_h.py +++ b/tests/test_h.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import itertools import math import operator diff --git a/tests/test_p.py b/tests/test_p.py index a38582e4..442e0598 100644 --- a/tests/test_p.py +++ b/tests/test_p.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import itertools import operator from collections import Counter diff --git a/tests/test_r.py b/tests/test_r.py index 1ba4b31a..a6b7455f 100644 --- a/tests/test_r.py +++ b/tests/test_r.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import operator import re diff --git a/tests/test_rng.py b/tests/test_rng.py index 1f90c686..4133e71e 100644 --- a/tests/test_rng.py +++ b/tests/test_rng.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - from random import Random from typing import Optional diff --git a/tests/test_types.py b/tests/test_types.py index c655aa88..8780ac5b 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -6,8 +6,6 @@ # software in any capacity. # ====================================================================================== -from __future__ import annotations - import pytest from dyce.types import is_even, is_odd