mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
* Bound AST nesting so deep source raises instead of crashing Deeply nested source exhausted the native stack and killed the process with SIGSEGV, which no Python-level `except` can catch. The parser grows its own stack when it runs low on one, so it returns trees deeper than the passes after it can walk. Those passes recurse without a limit of their own, and the symbol table, which does apply one, runs last. `compile(..., PyCF_ONLY_AST)` returns before reaching it at all. Apply that same limit to the tree right after it is parsed, and count bracket nesting before parsing rather than after, as CPython's tokenizer does. Checking afterwards built the tree first, and one nested that deep exhausts the stack when it is dropped. Fixes #7655 Assisted-by: Claude Code:Opus 5 * Return Result from too_deeply_nested_error Lets the four call sites use `?` instead of matching on `Some` and returning the error by hand, which drops 11 lines. `Result` is already `#[must_use]`, so the attribute on the function goes away with it. Assisted-by: Claude Code:Opus 5 * Return Result from pre_parse_source_error too Same shape as the previous commit, for the other check this PR adds, so the two are consistent with each other. Assisted-by: Claude Code:Opus 5 * Drop exceeds_max_nesting for the check beside it The escape-warning pass needs the bracket check but had no `SourceFile` to build a `CompileError` from, so it got a `bool` wrapper of its own. Building the `SourceFile` there lets it call `pre_parse_source_error` instead, which is shaped like the other checks in that file, and costs nothing measurable. Assisted-by: Claude Code:Opus 5
Test snippets
This directory contains two sets of test snippets which can be run in Python.
The snippets/ directory contains functional tests, and the benchmarks/
directory contains snippets for use in benchmarking RustPython's performance.
Setup
Our testing depends on pytest, which you can install using pip.
Running
Simply run pytest -v in this directory, and the tests should run (and hopefully
pass). If it hangs for a long time, that's because it's building RustPython in
release mode, which should take less time than it would to run every test
snippet with RustPython compiled in debug mode.