Skip to content

Commit 2f11ae4

Browse files
committed
fix pypy tests on windows
1 parent 0b31711 commit 2f11ae4

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/recursion_guard.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ pub struct RecursionGuard {
2020
}
2121

2222
// A hard limit to avoid stack overflows when rampant recursion occurs
23-
pub const RECURSION_GUARD_LIMIT: u16 = if cfg!(target_family = "wasm") { 50 } else { 255 };
23+
pub const RECURSION_GUARD_LIMIT: u16 = if cfg!(target_family = "wasm") || cfg!(all(target_os = "windows", PyPy)) {
24+
// wasm and windows PyPy have very limited stack sizes
25+
50
26+
} else if cfg!(PyPy) {
27+
// PyPy in general has more restricted stack space
28+
123
29+
} else {
30+
255
31+
};
2432

2533
impl RecursionGuard {
2634
// insert a new id into the set, return whether the set already had the id in it

tests/benchmarks/test_micro_benchmarks.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def definition_model_data():
274274
data = {'width': -1}
275275

276276
_data = data
277-
for i in range(100):
277+
for i in range(pydantic_core._pydantic_core._recursion_limit - 2):
278278
_data['branch'] = {'width': i}
279279
_data = _data['branch']
280280
return data
@@ -1189,14 +1189,15 @@ def f(v: int, info: core_schema.FieldValidationInfo) -> int:
11891189
return v + 1
11901190

11911191
schema: core_schema.CoreSchema = core_schema.int_schema()
1192+
limit = pydantic_core._pydantic_core._recursion_limit - 3
11921193

1193-
for _ in range(100):
1194+
for _ in range(limit):
11941195
schema = core_schema.field_after_validator_function(f, 'x', schema)
11951196

11961197
schema = core_schema.typed_dict_schema({'x': core_schema.typed_dict_field(schema)})
11971198

11981199
v = SchemaValidator(schema)
11991200
payload = {'x': 0}
1200-
assert v.validate_python(payload) == {'x': 100}
1201+
assert v.validate_python(payload) == {'x': limit}
12011202

12021203
benchmark(v.validate_python, payload)

0 commit comments

Comments
 (0)