You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
patchedast: no source regions for *args/**kwargs, positional-only and keyword-only parameters #994
Follow-up to #802 / #887, which give annotations of regular
function arguments their source regions in patchedast.
_PatchingASTWalker._arguments still walks only node.args:
*args and **kwargs are emitted as plain strings
("*", node.vararg.arg), so their arg nodes and annotations
(*args: int, **kwargs: str) get no region;
positional-only parameters (node.posonlyargs, before /) and
keyword-only parameters (node.kwonlyargs, after *), with
their defaults (kw_defaults) and annotations, are not walked
at all.
Source round trips still work, because unmatched text is kept as
whitespace/gap, but similar-code search and Restructure crash just
like #802 did. Verified with #887 applied:
fromrope.refactorimportsimilarfindersrc="def f(a, *, b: list):\n pass\n"# or "def f(*args: list): ..."list(similarfinder.RawSimilarFinder(src).get_matches("list"))
# AttributeError: 'Name' object has no attribute 'region'
#907 implemented this (walking posonlyargs with the / marker, kwonlyargs after *, annotated vararg/kwarg as nodes, and : annotation for every parameter), but it was closed without
being merged. Its approach, together with the tests from #887 as a
template (regions, round trips, RawSimilarFinder, Restructure),
is a good starting point.
Not to be confused with #898, which fixes scope bindings of
positional-only and keyword-only parameters, not their source
regions.
@marlon-costa-dc, your #907 already implemented exactly this
(walking posonlyargs with the / marker, kwonlyargs with kw_defaults after *, and annotated *args/**kwargs as
nodes), but it was closed on 2 December without a review. Its _arg hunk is identical to #887, which is now approved and waiting
for a second review.
Would you like to reopen it (or open a new PR) rebased on top of #887, limited to the _arguments part? The extract.py and
autoimport ride-alongs would be better as separate PRs. If we don't
hear from you within a few days, we'll pick up your _arguments
change ourselves, with credit (Co-authored-by:), so the fix
isn't lost.
Activity
mcepl commentedon Dec 3, 2026
@marlon-costa-dc, your #907 already implemented exactly this
(walking
posonlyargswith the/marker,kwonlyargswithkw_defaultsafter*, and annotated*args/**kwargsasnodes), but it was closed on 2 December without a review. Its
_arghunk is identical to #887, which is now approved and waitingfor a second review.
Would you like to reopen it (or open a new PR) rebased on top of
#887, limited to the
_argumentspart? Theextract.pyandautoimport ride-alongs would be better as separate PRs. If we don't
hear from you within a few days, we'll pick up your
_argumentschange ourselves, with credit (
Co-authored-by:), so the fixisn't lost.