Min/max for decimals() strategy stumbles with places.

14 views
Skip to first unread message

Jens Troeger

unread,
Jan 29, 2026, 9:27:53 PM (12 days ago) Jan 29
to Hypothesis users
Hello,

It looks like the ranges of the decimals() strategy shift/round when the places argument is used as well. For example (working but not a minimal example):

>>> min_ = decimal.Decimal(f"0.{'0'*63}1")
>>> max_ = decimal.Decimal(f"{'9'*64}.{'9'*64}")
>>> @hypothesis.given(st.decimals(min_value=min_, max_value=max_))
... def test(d):
...     assert min_ <= d <= max_

works just fine. However, add e.g. a places=2 argument then the generated values exceed the min/max range and the assertion fires:

>>> test()
    assert min_ <= d <= max_
           ^^^^^^^^^^^^^^^^^
AssertionError
Falsifying example: test(
    d=int_to_decimal(
        1_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000,
    ),
)

For now, using a filter() strategy works, but perhaps this should be handled by the strategy itself? I have a suspicion that the decimal context & rounding (docs) gets in the way here 🤔

Thanks!
Jens

Liam DeVoe

unread,
Jan 29, 2026, 10:17:09 PM (11 days ago) Jan 29
to Jens Troeger, Hypothesis users
Thanks Jens! This is clearly a bug, so I've filed an issue: https://github.com/HypothesisWorks/hypothesis/issues/4651.

--
You received this message because you are subscribed to the Google Groups "Hypothesis users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hypothesis-use...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/hypothesis-users/dce49cbc-d4a2-40e3-82b4-2c564de138b6n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages