Skip to content

fix(lint): avoid recursion failures in valid Python expressions - #760

Merged
rng1995 merged 2 commits into
NVIDIA:mainfrom
Afloat16:fix/lint-deep-python-expressions
Nov 17, 2026
Merged

rng1995 merged 2 commits into
NVIDIA:mainfrom
Afloat16:fix/lint-deep-python-expressions

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Summary

A valid Python script can have a deep expression tree without deeply nested control flow. The nesting check recursively visits every AST node, so a roughly 12 KB function with a 1,500-term addition raises RecursionError after parsing succeeds. A long attribute chain has the same effect. This aborts advisory lint before findings for that script or later files can be reported.

Walk the AST with an explicit stack carrying each node's control-flow depth. The recognized control-flow nodes, maximum-depth rule and advisory verdict remain unchanged. This addresses traversal of successfully parsed Python; it does not change parser-error handling.

Related changes in #677 added UTF-8 BOM support. This PR is based on main cbda65c1, including that change, and fixes the independent traversal failure.

Verification

Nine new cases: five fail and four compatibility controls pass against unchanged production. Real script files cover additions and attribute chains in both scripts/ and tools/, retained magic-number findings, continued checks on a second file and no false deep-nesting warning. Controls preserve flat, sibling, try/except and asynchronous depth semantics; a deep expression inside seven actual control-flow levels still measures seven.

  • python -m pytest tests/validators/test_script_lint.py -q — 29 passed on cbda65c1 plus this change, including the merged BOM regressions.

  • python -m ruff check src tests — passed.

  • Changed-file formatting and git diff --check — passed.

  • python -m build — wheel and sdist passed on the updated base.

  • I am familiar with the Contributing Guidelines

  • Added or updated focused tests

  • Updated documentation for user-visible changes (Unreleased changelog)

  • Ran make lint equivalent: python -m ruff check src tests

  • Full make test did not complete successfully in this environment (see below)

  • Ran make build equivalent: python -m build

  • Did not add credentials, private datasets, or proprietary benchmark content

The earlier full-suite attempt stops on unchanged base d2cb138 in test_gitlab_enriched_tier1_applies_the_keyless_job_baselines: its shell fixture hard-codes mktemp -d /tmp/..., while this workspace has no /tmp. That base run reached 456 passed, 2 skipped and 19 deselected before the failure.

Release Impact

  • Updated CHANGELOG.md

Use an explicit stack for control-flow depth so valid long binary and
attribute expressions cannot exhaust Python recursion during advisory lint.
Preserve existing control-flow node counting and continue later scripts.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
Resolve the Unreleased changelog insertion while preserving exactly
this pull request's code, tests, and release note against current main.

Signed-off-by: Afloat <ShuffleMonkey@163.com>

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution, @Afloat16. Reviewed c2653cde8ad1; no actionable defects found in the changed code.

Focused validation: 29 script-lint tests passed.

Hosted CI is still awaiting authorization or completion; this is a code-review approval, and does not certify a full hosted CI pass.

@rng1995
rng1995 merged commit 6e85d9b into NVIDIA:main Nov 17, 2026
25 checks passed
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.

2 participants