Repository navigation
Conversation
|
Complementary regions while reviewing this PR: the argument-annotation We split that delta into a branch with round-trip and match-region tests at |
|
This overlaps with #907, which includes the same regular-argument annotation fix alongside positional-only and keyword-only argument walking. My preference is to consolidate the implementation in #907, but keep the additional coverage here. In particular, the Restructure replacement and annotation-matching tests exercise useful paths beyond AST round trips. Could you coordinate with #907's author to carry those tests over? Please keep this PR open until the combined change lands and its coverage is verified. If the broader parameter work stalls, this remains a useful smaller fix to merge independently. |
Visit each argument's annotation so structural searches and replacements can use its source region. Cover the reported wildcard crash, nested annotations, defaults, and source round trips. Based on the diagnosis and proposed fix in issue python-rope#802.
777bfc9 to
83ee137
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #887 +/- ##
==========================================
+ Coverage 95.48% 95.51% +0.02%
==========================================
Files 134 134
Lines 27127 27171 +44
==========================================
+ Hits 25902 25952 +50
+ Misses 1225 1219 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mcepl
left a comment
There was a problem hiding this comment.
#907 was closed without being merged, so as discussed earlier this
smaller fix goes in on its own. Approved.
I rebased the branch onto current master and resolved the
conflicts: similarfindertest.py now keeps both your new tests and
the class-header test from #990, and the changelog entry moved from
CHANGELOG.md to changelog.d/887.md (see
changelog.d/README.md). The commit is otherwise unchanged.
Verified:
- All 5 new tests fail on master (e.g.
RawSimilarFinderon
def foo(l: list)raisesAttributeError: 'Name' object has no attribute 'region') and pass here. - No regressions in source round trips for regular, annotated,
positional-only, keyword-only, annotated*args/**kwargs,
async defand lambda signatures. - Full suite passes locally (2209 passed); CI is green on all 24
checks (two macOS jobs needed a re-run after a runner shortage).
Non-blocking note: annotations on *args/**kwargs and on
positional-only/keyword-only parameters still get no regions,
because _arguments walks only node.args and emits varargs as
plain strings. That was the remaining part of #907; worth a
follow-up, but out of scope here, as the PR says.
Description
Searching a parameter annotation such as
def foo(items: list): ...raisesAttributeErrorbecause_argleaves the annotation without a source region. Visit the annotation with the existing child-node handler, following v587su's proposed fix in #802.Regression tests cover exact source regions, source round trips, wildcard matching, and an actual
Restructurereplacement of nested annotations with defaults. The change covers regular function arguments.Fixes #802
Checklist
Validation on Windows with Python 3.12.14: all five new regression tests fail against the original module and pass with the fix. Full suite: 2,153 passed, 12 skipped, 5 xfailed. Targeted Black and isort checks pass; wheel and sdist builds pass.