Skip to content

fix pypy tests on windows #757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/recursion_guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ pub struct RecursionGuard {
}

// A hard limit to avoid stack overflows when rampant recursion occurs
pub const RECURSION_GUARD_LIMIT: u16 = if cfg!(target_family = "wasm") { 50 } else { 255 };
pub const RECURSION_GUARD_LIMIT: u16 = if cfg!(any(target_family = "wasm", all(windows, PyPy))) {
// wasm and windows PyPy have very limited stack sizes
50
} else if cfg!(any(PyPy, windows)) {
// PyPy and Windows in general have more restricted stack space
100
} else {
255
};

impl RecursionGuard {
// insert a new id into the set, return whether the set already had the id in it
Expand Down
7 changes: 4 additions & 3 deletions tests/benchmarks/test_micro_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def definition_model_data():
data = {'width': -1}

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

schema: core_schema.CoreSchema = core_schema.int_schema()
limit = pydantic_core._pydantic_core._recursion_limit - 3

for _ in range(100):
for _ in range(limit):
schema = core_schema.field_after_validator_function(f, 'x', schema)

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

v = SchemaValidator(schema)
payload = {'x': 0}
assert v.validate_python(payload) == {'x': 100}
assert v.validate_python(payload) == {'x': limit}

benchmark(v.validate_python, payload)