Skip to content

test: pass the Python suite on PyPy 3.11 - #474

Merged
JuroOravec merged 2 commits into
mainfrom
test/pass-on-pypy
Oct 28, 2026
Merged

JuroOravec merged 2 commits into
mainfrom
test/pass-on-pypy

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

Prepares #264. The new weekly workflow runs the Python suite on PyPy 3.11 and free-threaded CPython 3.14. This PR fixes what failed on PyPy, so that workflow can start green.

What failed

A local run of main (4ec0dd1) on PyPy 3.11.17 gave 45 failed, 13490 passed and 1039 skipped. The run used the same selection as CI, plus -v -rfE -o faulthandler_timeout=600. Free-threaded 3.14 already passed in CI. The hang seen in the first CI trial did not reproduce locally.

Group Tests Cause Change
Row HTML writer 43 in test_simple_vue_row_html.py The writer runs only with markupsafe's C escaper. That check is a deliberate safety guard, and PyPy has no C speedups. Tests now read the real flag. Where the result still means something, they assert the per-row result instead of skipping. A new test checks that CPython detects the C escaper, which the old tests pinned only by accident.
Native render 1 run_on_path(rust=True) turned the Rust path on even where it is unsupported. Skip inside run_on_path, using the house reason. test_the_rust_path_is_on_where_it_is_supported still fails a broken CPython build.
Error text 1 PyPy words the TypeError differently. Take the expected text from the interpreter.
Record stubs 1 PyPy lists __dict__ and __weakref__ on Rust classes. Leave out those two names.
i18n collection 1 No reference counting on PyPy. One more gc.collect(); a real leak still fails.
Deep nesting 1 PyPy has no 20-nested-blocks limit. Skip when the interpreter compiles the deep function; on CPython it must still raise SyntaxError.
Const concurrency 1 Not a product race. Since #319, a Const body is prepared with no lock held, and the cache keeps the first stored body under its lock (performance/const.md). The old calls == 1 test passed only by thread timing. Replaced by a barrier test: four overlapping builds, each with a different value, must all render the first stored body. It fails on last-writer-wins, and it times out on a return to building under the lock.
Builtins with the sandbox off 1 On PyPy, eval finds builtins even with an empty read-only __builtins__. With sandbox_expressions=False, every builtin is available there. Documented, see below. The test is split: the read-only shared mapping is checked everywhere, and the no-builtins check skips where eval still finds them.

Docs

  • The PyPy builtins difference is documented in the new "Differences on PyPy" section of about/compatibility.md, in "Turn the sandbox off" on security.md, and in the compile_expr docstring.
  • These places present the sandbox-off mode for trusted templates only. With the sandbox off, a template can already reach any Python object on CPython too, so this is a difference in output, not in who to trust. A missing variable named like a builtin, such as {{ id }}, renders on PyPy instead of failing. I confirmed that by rendering through Citry on PyPy.
  • No CHANGELOG entry: behavior is unchanged, it is only documented now.

Evidence

  • CPython: the changed test files plus the native render files give 537 passed.
  • PyPy 3.11.17: the touched files give 609 passed, 297 skipped, 0 failed.
  • The Const test passed 15 of 15 repeated -n 4 runs on each interpreter.
  • ruff passes. mypy on eval.py passes, default and --platform linux.
  • Reviews: an independent review and a docs cold read; every finding is folded in.
  • Not yet run on PyPy: docs_site/tests and the qualification frame-budget tests. Neither is in the weekly workflow's selection.
  • Cargo is left to CI.

🤖 Generated with Claude Code

JuroOravec and others added 2 commits October 27, 2026 20:43
Several tests relied on CPython behavior that PyPy does not share. Each
now checks the capability it depends on:

- The row HTML tests check whether markupsafe's C escaper is in use.
  Citry turns the row HTML writer on only then, so on PyPy they check
  the per-row output and skip the test that counts work the writer saves.
  A new test requires CPython to detect the C escaper, so CPython cannot
  quietly fall back to testing only the per-row path.
- run_on_path skips a forced Rust run when the interpreter has no
  native render module, instead of failing inside Citry.
- The f-string error test compares against the interpreter's own
  TypeError text.
- The browser record stub test ignores the __dict__ and __weakref__
  descriptors PyPy adds to classes built in Rust.
- The i18n catalog test collects once more, since without reference
  counting the catalog is freed on the pass after its class.
- The deep read set test still requires CPython to reject the deep
  function, and skips on an interpreter that compiles it, because
  Citry's fallback then never runs.
- The concurrent Const test now pins the contract Citry documents:
  threads that render the same new Const values at once may each
  prepare the body, and every render shows the first body stored. A
  barrier makes the builds overlap on every run, so the test no longer
  depends on thread timing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With sandbox_expressions=False, Citry runs template expressions with
an empty __builtins__ mapping so they cannot call len or other
builtins, matching the sandbox. PyPy's eval finds builtins anyway, so
on PyPy a trusted template such as {{ len(items) }} renders with the
sandbox off, while CPython and the sandbox reject it.

The compatibility page (under a new "Differences on PyPy" heading),
the security page, and compile_expr now say so. The test that checks
builtins are hidden is split in two: the check that a template cannot
change the shared `__builtins__` mapping runs everywhere, and the
no-builtins check skips when the interpreter's eval still finds them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit 34700e4 into main Oct 28, 2026
31 of 35 checks passed
@JuroOravec
JuroOravec deleted the test/pass-on-pypy branch October 28, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant