Skip to content

Commit 8869509

Browse files
Set lineno and end_lineno on Arguments (#2865)
1 parent 4a7e23f commit 8869509

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Release date: TBA
1616
Closes #2741
1717
Closes pylint-dev/pylint#6094
1818

19+
* ``lineno`` and ``end_lineno`` are now available on ``Arguments``.
20+
1921
* Add helper to iterate over all annotations nodes of function arguments,
2022
``Arguments.get_annotations()``.
2123

astroid/rebuilder.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from __future__ import annotations
1010

1111
import ast
12+
import itertools
1213
import sys
1314
import token
1415
from collections.abc import Callable, Collection, Generator
@@ -589,6 +590,16 @@ def visit_arguments(
589590
type_comment_kwonlyargs=type_comment_kwonlyargs,
590591
type_comment_posonlyargs=type_comment_posonlyargs,
591592
)
593+
if start_end_lineno_pairs := [
594+
(arg.lineno, arg.end_lineno)
595+
for arg in itertools.chain(
596+
node.args, node.posonlyargs, node.kwonlyargs, [node.vararg, node.kwarg]
597+
)
598+
if arg
599+
]:
600+
newnode.lineno = min(startend[0] for startend in start_end_lineno_pairs)
601+
newnode.end_lineno = max(startend[1] for startend in start_end_lineno_pairs)
602+
592603
# save argument names in locals:
593604
assert newnode.parent
594605
if vararg:

tests/test_nodes_lineno.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,8 @@ async def func(): #@
589589
assert (f1.body[0].lineno, f1.body[0].col_offset) == (6, 4)
590590
assert (f1.body[0].end_lineno, f1.body[0].end_col_offset) == (6, 8)
591591

592+
assert (f1.args.lineno, f1.args.end_lineno) == (2, 4)
593+
592594
# pos only arguments
593595
# TODO fix column offset: arg -> arg (AssignName)
594596
assert isinstance(f1.args.posonlyargs[0], nodes.AssignName)

0 commit comments

Comments
 (0)