Repository navigation
Compute scope regions from native AST positions - #909
Open
marlon-costa-dc wants to merge 1 commit into
Open
marlon-costa-dc wants to merge 1 commit into
marlon-costa-dc wants to merge 1 commit into
Conversation
Scope.get_region() no longer patches the whole module AST through patchedast to borrow node regions. It now resolves each scope's region directly from the native AST positions via codeanalyze.ASTLinesAdapter, and extends it to the enclosing decorator by searching backwards for the "@" token with _Source.rfind_token. This keeps regions correct for sources the patched walker cannot round-trip: normalized Unicode identifiers (e.g. "u\u0301" aliases), decorated definitions, and raw string sources using LF, CRLF, or CR newlines. Modules resolve to the full source range, and nodes without complete end positions raise RopeError instead of silently producing partial regions. Note: the original internal change also fixed _Source tokenization for CR/CRLF sources; that code path was removed by the patchedast cleanup (python-rope#896), which already computes positions through ASTLinesAdapter, so only the pyscopes resolution is carried over.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #909 +/- ##
==========================================
+ Coverage 95.34% 95.37% +0.02%
==========================================
Files 134 134
Lines 26762 26846 +84
==========================================
+ Hits 25516 25604 +88
+ Misses 1246 1242 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pyscopes.get_regiondelegated topatchedast.patch_aston the whole module — expensive for every scope query and wrong on modules patchedast cannot walk (unpatchable constructs, exotic newlines). It also mis-derived decorator starts.Compute the region from the node's native AST positions (module = whole source), locating the
@of decorators via a reverse token search, handling Module/LF/CRLF/CR and normalized Unicode identifiers. Falls back to rope's own error when positions are incomplete.pyscopestest: 53 passed + 18 subtests; patchedast/codeanalyze suites unaffected locally on 3.13.