Repository navigation
Commit 3e7d11e
Keep int bounds exact, like the Decimal ones
`ensure_is_finite_numeric` converted int bounds with `PyLong_AsDouble`
and never checked the result. For an int outside the range of a double
the `OverflowError` was left pending and the function still returned
true, so `Meta(gt=10**400)` surfaced as `SystemError`, and for
`multiple_of` the `-1.0` sentinel tripped the `<= 0` check and reported
a large positive bound as non-positive. On this branch the misreport got
worse: `Meta(gt=10**400, lt=Decimal("5"))` blamed `decimal.Decimal`.
Rejecting those ints is not an option here, because `Meta` already
treats the two spellings as one value: `Meta(gt=10**400)` and
`Meta(gt=Decimal("1E+400"))` compare equal, hash equal, and collapse to
a single object inside `Annotated`. Accepting one and refusing the other
would also contradict this branch's own argument that a double is the
wrong gate for large-but-finite bounds.
So drop the double entirely for ints. Every int is finite, and the only
remaining check, positivity for `multiple_of`, is done exactly against
zero, which is what the Decimal branch already does; that block is
factored out into `ensure_is_positive` and shared.
Whether a bound is usable stays a per-type question, decided where the
annotated type is known, as it already was for `Meta(gt=2**64)`: int64
for `int` targets, float64 for `float` targets, exact for `Decimal`
targets. `_constr_as_f64` grows the missing half of that, turning the
overflow into the same kind of message `_constr_as_i64` already gives
instead of relying on an invariant that only held because the bug
crashed first.
Co-Authored-By: Claude Opus 5 <[email protected]>1 parent f71e100 commit 3e7d11e
3 files changed
Lines changed: 100 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
128 | 136 | | |
129 | 137 | | |
130 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1730 | 1730 | | |
1731 | 1731 | | |
1732 | 1732 | | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
1733 | 1747 | | |
1734 | 1748 | | |
1735 | 1749 | | |
1736 | | - | |
1737 | 1750 | | |
1738 | | - | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
1739 | 1760 | | |
1740 | 1761 | | |
1741 | | - | |
| 1762 | + | |
1742 | 1763 | | |
1743 | 1764 | | |
1744 | 1765 | | |
| |||
1747 | 1768 | | |
1748 | 1769 | | |
1749 | 1770 | | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
1750 | 1776 | | |
1751 | 1777 | | |
1752 | 1778 | | |
| |||
1792 | 1818 | | |
1793 | 1819 | | |
1794 | 1820 | | |
1795 | | - | |
1796 | | - | |
1797 | | - | |
1798 | | - | |
1799 | | - | |
1800 | | - | |
1801 | | - | |
1802 | | - | |
1803 | | - | |
1804 | | - | |
1805 | | - | |
1806 | | - | |
1807 | | - | |
1808 | | - | |
1809 | | - | |
1810 | | - | |
1811 | | - | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
1812 | 1824 | | |
1813 | 1825 | | |
1814 | 1826 | | |
1815 | 1827 | | |
1816 | | - | |
1817 | | - | |
1818 | | - | |
1819 | | - | |
1820 | | - | |
1821 | 1828 | | |
1822 | 1829 | | |
1823 | 1830 | | |
| |||
3827 | 3834 | | |
3828 | 3835 | | |
3829 | 3836 | | |
3830 | | - | |
3831 | | - | |
| 3837 | + | |
| 3838 | + | |
| 3839 | + | |
| 3840 | + | |
| 3841 | + | |
| 3842 | + | |
| 3843 | + | |
| 3844 | + | |
| 3845 | + | |
| 3846 | + | |
| 3847 | + | |
| 3848 | + | |
| 3849 | + | |
3832 | 3850 | | |
3833 | 3851 | | |
3834 | 3852 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
176 | 200 | | |
177 | 201 | | |
178 | 202 | | |
| |||
314 | 338 | | |
315 | 339 | | |
316 | 340 | | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
317 | 346 | | |
318 | 347 | | |
319 | 348 | | |
| |||
395 | 424 | | |
396 | 425 | | |
397 | 426 | | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
398 | 432 | | |
399 | 433 | | |
400 | 434 | | |
| |||
540 | 574 | | |
541 | 575 | | |
542 | 576 | | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
543 | 590 | | |
544 | 591 | | |
545 | 592 | | |
| |||
0 commit comments