Skip to content

Commit a4d4154

Browse files
committed
Fix PyPy numeric handling issues
- Normalise -0.0 to 0.0 in get_number_bounds for consistent comparisons - Convert whole-number float multipleOf values to int for proper type inference - Use PyPy 3.11 in CI
1 parent 2523a98 commit a4d4154

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
runs-on: ubuntu-latest
2727
strategy:
2828
matrix:
29-
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "pypy-3.10"]
29+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "pypy-3.11"]
3030
fail-fast: false
3131
steps:
3232
- uses: actions/checkout@v6

src/hypothesis_jsonschema/_canonicalise.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,15 @@ def get_number_bounds(
219219
if lo < lower:
220220
lo = next_up(lo)
221221
exmin = False
222-
lower = lo
222+
# Normalise -0.0 to 0.0 for consistent comparisons (especially on PyPy)
223+
lower = lo + 0.0
223224
if upper is not None:
224225
hi = float(upper)
225226
if hi > upper:
226227
hi = next_down(hi)
227228
exmax = False
228-
upper = hi
229+
# Normalise -0.0 to 0.0 for consistent comparisons (especially on PyPy)
230+
upper = hi + 0.0
229231
return lower, upper, exmin, exmax
230232

231233

@@ -311,9 +313,13 @@ def canonicalish(schema: JSONType) -> dict[str, Any]:
311313
k: v if isinstance(v, list) else canonicalish(v)
312314
for k, v in schema[key].items()
313315
}
314-
# multipleOf is semantically unaffected by the sign, so ensure it's positive
316+
# multipleOf is semantically unaffected by the sign, so ensure it's positive.
317+
# Also normalise whole-number floats to ints for consistent isinstance checks.
315318
if "multipleOf" in schema:
316-
schema["multipleOf"] = abs(schema["multipleOf"])
319+
mul = abs(schema["multipleOf"])
320+
if isinstance(mul, float) and mul.is_integer():
321+
mul = int(mul)
322+
schema["multipleOf"] = mul
317323

318324
type_ = get_type(schema)
319325
if "number" in type_:

0 commit comments

Comments
 (0)