Avatar for the msgspec user
msgspec
msgspec
BlogDocsChangelog

Performance History

Latest Results

Merge remote-tracking branch 'origin/main' into HEAD
fix-profile-workflow-benchmark-flags
9 days ago
Merge branch 'main' into fix-raw-yaml-decode-error
Brohammad:fix-raw-yaml-decode-error
9 days ago
Test Meta length bounds at platform limits
meta-bounds-overflow
9 days ago
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 <noreply@anthropic.com>
decimal-constraints-683
9 days ago
Fix SystemError when convert()'ing an out-of-range int to float (#1162) ## Summary `msgspec.convert(obj, float)` converts a Python `int` to a C `double` via `PyLong_AsDouble` without checking for overflow. For an `int` too large to represent as a finite `float` (e.g. `10**400`), `PyLong_AsDouble` sets `OverflowError` internally but still returns `-1.0`, and that value was passed straight through to `ms_decode_float` and returned to the interpreter with the exception still set — which surfaces as: ``` SystemError: <built-in function convert> returned a result with an exception set ``` This bypasses the documented `ValidationError` contract entirely, so a caller wrapping the call in `except msgspec.ValidationError` doesn't catch it. `json.decode` already handles the equivalent case correctly, raising `ValidationError: Number out of range`. This PR applies the same "check `PyErr_Occurred()` after a lossy C conversion, then report via `ms_error_with_path`" pattern already used elsewhere in this file (e.g. `_constr_as_f64`), so `convert()` reports the overflow the same way — for both bare (`convert(big, float)`) and nested (`convert({"x": big}, dict[str, float])`) targets, under both `strict=True` and `strict=False`. Fixes #1122. ## Testing - Reverted the fix locally and reproduced the exact reported `SystemError` before reapplying it. - Added `test_float_from_int_out_of_range` to `TestFloat` in `tests/unit/test_convert.py`, covering bare and nested targets under both strict modes. - Ran the full `tests/unit/` suite: 6052 passed, 473 skipped, 0 failures.
main
9 days ago

Latest Branches

CodSpeed Performance Gauge
0%
Restore pytest-benchmark for local and manual profiling#1113
9 days ago
81cf3aa
fix-profile-workflow-benchmark-flags
CodSpeed Performance Gauge
0%
Clarify msgspec.Raw unsupported with yaml/toml decode#1170
9 days ago
de14bfb
Brohammad:fix-raw-yaml-decode-error
CodSpeed Performance Gauge
-10%
Correct error messages for out-of-range Meta length bounds#1172
9 days ago
ededd5b
meta-bounds-overflow
Ā© 2026 CodSpeed Technology
Home Terms Privacy Docs