Skip to content

patchedast: no source regions for *args/**kwargs, positional-only and keyword-only parameters #994

Backlog

Description

@mcepl

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:

from rope.refactor import similarfinder
src = "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'

(def f(a: list) works with #887.)

#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.

Activity

  1. mcepl commented on Dec 3, 2026

    @mcepl
    ContributorAuthor

    @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions