Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Release date: TBA
Closes #2741
Closes pylint-dev/pylint#6094

* ``lineno`` and ``end_lineno`` are now available on ``Arguments``.

* Add helper to iterate over all annotations nodes of function arguments,
``Arguments.get_annotations()``.

Expand Down
11 changes: 11 additions & 0 deletions astroid/rebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from __future__ import annotations

import ast
import itertools
import sys
import token
from collections.abc import Callable, Collection, Generator
Expand Down Expand Up @@ -589,6 +590,16 @@ def visit_arguments(
type_comment_kwonlyargs=type_comment_kwonlyargs,
type_comment_posonlyargs=type_comment_posonlyargs,
)
if start_end_lineno_pairs := [
(arg.lineno, arg.end_lineno)
for arg in itertools.chain(
node.args, node.posonlyargs, node.kwonlyargs, [node.vararg, node.kwarg]
)
if arg
]:
newnode.lineno = min(startend[0] for startend in start_end_lineno_pairs)
newnode.end_lineno = max(startend[1] for startend in start_end_lineno_pairs)

# save argument names in locals:
assert newnode.parent
if vararg:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_nodes_lineno.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,8 @@ async def func(): #@
assert (f1.body[0].lineno, f1.body[0].col_offset) == (6, 4)
assert (f1.body[0].end_lineno, f1.body[0].end_col_offset) == (6, 8)

assert (f1.args.lineno, f1.args.end_lineno) == (2, 4)

# pos only arguments
# TODO fix column offset: arg -> arg (AssignName)
assert isinstance(f1.args.posonlyargs[0], nodes.AssignName)
Expand Down
Loading