Repository navigation
[Dynamo] Fix stale funcname scope for one-line definitions - #199357
Mohit-25-tech wants to merge 1 commit into
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - Ready for human review:
Findings (1): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/199357
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 10eff85 with merge base 68f0e54 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
|
|
Thanks for the additional validation! The AST comparison across the PyTorch source tree is really helpful confirmation that the fix handles the single-line definition cases correctly without introducing incorrect qualified names. I'll keep this validation in mind as I finalize the PR. |
|
@pytorchbot label "topic: not user facing" |
|
@pytorchbot triage |
|
Hi maintainers, A quick follow-up on this PR. The linked issue #199314 is now marked actionable, and the latest displayed checks, including EasyCLA, are passing. Could one of the requested reviewers take a look at the implementation when convenient? I'd appreciate feedback on the scope-handling approach and am happy to make any necessary adjustments. Thanks for your time! |
|
@pytorchbot merge -r |
|
Pull workflow has not been scheduled for the PR yet. It could be because author doesn't have permissions to run those or skip-checks keywords were added to PR/commits, aborting merge. Please get/give approval for the workflows and/or remove skip ci decorators before next merge attempt. If you think this is a mistake, please contact PyTorch Dev Infra. |
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
The source-name cache removes definition scopes on DEDENT, which is absent for same-line bodies. Those names therefore leaked into subsequent source lines. Pop a definition after its logical newline when the next significant token is not INDENT, preserving the name on the declaration itself. Add coverage for one-line classes, functions, overloads and async functions, alongside nested scopes and multiline signatures with comments before the body. Fixes pytorch#199314 Test Plan: Used a prebuilt CPU nightly and loaded the modified parser into the installed package with the temporary run_funcname_tests.py bootstrap; no source build. ```powershell $env:TORCHINDUCTOR_WINDOWS_TESTS='1' .venv/Scripts/python.exe -I agent_space/run_funcname_tests.py test_misc.py MiscTests.test_funcname_cache MiscTests.test_funcname_cache_single_line -v .venv/Scripts/python.exe -I agent_space/run_funcname_tests.py test_logging.py -k trace_source -v .venv/Scripts/python.exe -I agent_space/run_funcname_tests.py test_logging.py -k trace_call -v .venv/Scripts/python.exe -I agent_space/check_funcname_scopes.py .venv/Scripts/python.exe -I agent_space/run_funcname_typecheck.py .venv/Scripts/python.exe -I agent_space/run_python_lint.py --fix git diff --check -- torch/_dynamo/funcname_cache.py test/dynamo/test_misc.py ``` The new regression passed and its snapshot failed against the original parser. Ten AST scope checks and the Module._call_impl reproduction passed. Five trace_source tests passed; the simple test hit a fallback because MSVC is absent. The existing funcname test is skipped on Windows; four trace_call tests require Python >=3.11 and were skipped on Python 3.10. Pyrefly reported zero errors. The seven selected Python linters passed via Spin's helper. A temporary wrapper normalized Windows extended paths for the unchanged official formatter. Prepared with assistance from Codex.
|
Successfully rebased |
b32ba17 to
10eff85
Compare
There was a problem hiding this comment.
Automated review of 10eff85: nothing blocking; ready for human review.
This PR fixes torch/_dynamo/funcname_cache.py so that a one-line def or class (body on the header line) closes its own scope at its logical NEWLINE, and it adds a regression test in test/dynamo/test_misc.py. The review recommends Approve: nothing blocks the PR, and the only remaining point is a cosmetic naming nit.
⚪ 1 non-blocking finding
pytorch/torch/_dynamo/funcname_cache.py
Line 72 in 10eff85
Non-blocking, carried over from the last review: next_token holds an index (it is used as tokens\[next_token\]), not a token. That clashes with the loop's i/token naming, and j or next_idx would read better. The next_token == len(tokens) check on line 78 can never be true, because generate_tokens always ends with ENDMARKER and a failed tokenize never produces a partial list. The check is harmless and matches the defensive bounds check on line 57, so keeping it is fine.
This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Issue being fixed
BC-breaking?
Summary (human written only)
Fix stale function/class scopes in Dynamo's source-name cache for one-line
definitions.
Agent details
cc @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @amjames @jataylo @azahed98