diff --git a/src/icepool/function.py b/src/icepool/function.py index afceeaa2..ace6f0d7 100644 --- a/src/icepool/function.py +++ b/src/icepool/function.py @@ -555,7 +555,7 @@ def map( of the process up to this point. If you only want to reroll the current stage, you can nest another `map` inside `repl`. - EXPERIMENTAL: If set to `None`, the result will be as if this + EXPERIMENTAL: If set to `'inf'`, the result will be as if this were repeated an infinite number of times. In this case, the result will be in simplest form. time_limit: Similar to `repeat`, but will return early if a fixed point diff --git a/src/icepool/population/die.py b/src/icepool/population/die.py index b2f10d34..4df29544 100644 --- a/src/icepool/population/die.py +++ b/src/icepool/population/die.py @@ -18,6 +18,7 @@ import itertools import math import operator +import warnings from typing import Any, Callable, Collection, Container, Iterable, Iterator, Literal, Mapping, MutableMapping, Sequence, Set, cast, overload @@ -304,7 +305,7 @@ def reroll(self, /, *, star: bool | None = None, - depth: int | None) -> 'Die[T_co]': + depth: int | Literal['inf']) -> 'Die[T_co]': """Rerolls the given outcomes. Args: @@ -330,7 +331,12 @@ def reroll(self, else: outcome_set = self._select_outcomes(which, star) - if depth is None: + if depth == 'inf' or depth is None: + if depth is None: + warnings.warn( + "depth=None is deprecated; use depth='inf' instead.", + category=DeprecationWarning, + stacklevel=1) data = { outcome: quantity for outcome, quantity in self.items() @@ -359,7 +365,7 @@ def filter(self, /, *, star: bool | None = None, - depth: int | None) -> 'Die[T_co]': + depth: int | Literal['inf']) -> 'Die[T_co]': """Rerolls until getting one of the given outcomes. Essentially the complement of `reroll()`. @@ -624,9 +630,9 @@ def mean_time_to_sum(self: 'Die[int]', target: int, /) -> Fraction: self.denominator() - self.quantity(0)) for i in range(len(self._mean_time_to_sum_cache), target + 1): - result = time_per_effect + self.reroll( - [0], - depth=None).map(lambda x: self.mean_time_to_sum(i - x)).mean() + result = time_per_effect + self.reroll([ + 0 + ], depth='inf').map(lambda x: self.mean_time_to_sum(i - x)).mean() self._mean_time_to_sum_cache.append(result) return result diff --git a/tests/again_test.py b/tests/again_test.py index 375481e7..ad06d7a2 100644 --- a/tests/again_test.py +++ b/tests/again_test.py @@ -102,7 +102,7 @@ def test_is_additive(): def test_again_count(n): count = Die([1, 2, 3, 4, 5, 6 + Again], again_count=n) depth = d6.explode(depth=n) - depth = depth.reroll([depth.max_outcome()], depth=None) + depth = depth.reroll([depth.max_outcome()], depth='inf') assert count == depth @@ -115,5 +115,5 @@ def test_again_count_double_blocked(): def test_again_count_double(): result = Die([1, 2, 3, 4, 5, 6 + Again + Again], again_count=2) bonus = 2 @ d6.map({6: 100}) - expected = d6.map({6: 6 + bonus}).reroll(lambda x: x > 100, depth=None) + expected = d6.map({6: 6 + bonus}).reroll(lambda x: x > 100, depth='inf') assert result == expected diff --git a/tests/reroll_test.py b/tests/reroll_test.py index 91961e9f..f8f2d8d4 100644 --- a/tests/reroll_test.py +++ b/tests/reroll_test.py @@ -3,19 +3,19 @@ def test_reroll_default(): - result = icepool.d6.reroll(depth=None) + result = icepool.d6.reroll(depth='inf') expected = icepool.d5 + 1 assert result.equals(expected) def test_reroll_1(): - result = icepool.d6.reroll([1], depth=None) + result = icepool.d6.reroll([1], depth='inf') expected = icepool.d5 + 1 assert result.equals(expected) def test_reroll_2(): - result = icepool.d6.reroll([1, 2], depth=None) + result = icepool.d6.reroll([1, 2], depth='inf') expected = icepool.d4 + 2 assert result.equals(expected) @@ -62,18 +62,18 @@ def test_reroll_depth_3_mixed(): def test_infinite_reroll(): - assert icepool.d4.reroll([1, 2, 3, 4], depth=None).is_empty() + assert icepool.d4.reroll([1, 2, 3, 4], depth='inf').is_empty() def test_reroll_multidim(): result = icepool.Die([(1, 0), (0, 1)]).reroll(lambda x: x[0] == 0, - depth=None) + depth='inf') expected = icepool.Die([(1, 0)]) assert result.equals(expected) def test_reroll_until_multidim(): result = icepool.Die([(1, 0), (0, 1)]).filter(lambda x: x[0] == 0, - depth=None) + depth='inf') expected = icepool.Die([(0, 1)]) assert result.equals(expected) diff --git a/tests/vector_test.py b/tests/vector_test.py index 676b70c0..01f013de 100644 --- a/tests/vector_test.py +++ b/tests/vector_test.py @@ -58,17 +58,17 @@ def test_map_star(): def test_reroll_star(): result = icepool.vectorize(d6, d6) - result = result.reroll(lambda a, b: a == 6 and b == 6, depth=None) + result = result.reroll(lambda a, b: a == 6 and b == 6, depth='inf') result = result.map(lambda a, b: a + b) - expected = (2 @ icepool.d6).reroll({12}, depth=None) + expected = (2 @ icepool.d6).reroll({12}, depth='inf') assert result.equals(expected) def test_filter_star(): result = icepool.vectorize(d6, d6) - result = result.filter(lambda a, b: a == 6 and b == 6, depth=None) + result = result.filter(lambda a, b: a == 6 and b == 6, depth='inf') result = result.map(lambda a, b: a + b) - expected = (2 @ icepool.d6).filter({12}, depth=None) + expected = (2 @ icepool.d6).filter({12}, depth='inf') assert result.equals(expected)