Skip to content

Commit d5e0838

Browse files
authored
improvement: shift node location attributes to classes which have them
1 parent 72623c6 commit d5e0838

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

stdlib/_ast.pyi

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ class AST:
1919
_fields: ClassVar[tuple[str, ...]]
2020
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
2121
# TODO: Not all nodes have all of the following attributes
22-
lineno: int
23-
col_offset: int
24-
end_lineno: int | None
25-
end_col_offset: int | None
2622
type_comment: str | None
2723

2824
class mod(AST): ...
@@ -55,7 +51,11 @@ class Expression(mod):
5551
__match_args__ = ("body",)
5652
body: expr
5753

58-
class stmt(AST): ...
54+
class stmt(AST):
55+
lineno: int
56+
col_offset: int
57+
end_lineno: int | None
58+
end_col_offset: int | None
5959

6060
class FunctionDef(stmt):
6161
if sys.version_info >= (3, 12):
@@ -227,7 +227,12 @@ class Expr(stmt):
227227
class Pass(stmt): ...
228228
class Break(stmt): ...
229229
class Continue(stmt): ...
230-
class expr(AST): ...
230+
231+
class expr(AST):
232+
lineno: int
233+
col_offset: int
234+
end_lineno: int | None
235+
end_col_offset: int | None
231236

232237
class BoolOp(expr):
233238
if sys.version_info >= (3, 10):
@@ -468,7 +473,11 @@ class comprehension(AST):
468473
ifs: list[expr]
469474
is_async: int
470475

471-
class excepthandler(AST): ...
476+
class excepthandler(AST):
477+
lineno: int
478+
col_offset: int
479+
end_lineno: int | None
480+
end_col_offset: int | None
472481

473482
class ExceptHandler(excepthandler):
474483
if sys.version_info >= (3, 10):
@@ -489,18 +498,30 @@ class arguments(AST):
489498
defaults: list[expr]
490499

491500
class arg(AST):
501+
lineno: int
502+
col_offset: int
503+
end_lineno: int | None
504+
end_col_offset: int | None
492505
if sys.version_info >= (3, 10):
493506
__match_args__ = ("arg", "annotation", "type_comment")
494507
arg: _Identifier
495508
annotation: expr | None
496509

497510
class keyword(AST):
511+
lineno: int
512+
col_offset: int
513+
end_lineno: int | None
514+
end_col_offset: int | None
498515
if sys.version_info >= (3, 10):
499516
__match_args__ = ("arg", "value")
500517
arg: _Identifier | None
501518
value: expr
502519

503520
class alias(AST):
521+
lineno: int
522+
col_offset: int
523+
end_lineno: int | None
524+
end_col_offset: int | None
504525
if sys.version_info >= (3, 10):
505526
__match_args__ = ("name", "asname")
506527
name: str
@@ -518,7 +539,12 @@ if sys.version_info >= (3, 10):
518539
subject: expr
519540
cases: list[match_case]
520541

521-
class pattern(AST): ...
542+
class pattern(AST):
543+
lineno: int
544+
col_offset: int
545+
end_lineno: int
546+
end_col_offset: int
547+
522548
# Without the alias, Pyright complains variables named pattern are recursively defined
523549
_Pattern: typing_extensions.TypeAlias = pattern
524550

@@ -568,6 +594,8 @@ if sys.version_info >= (3, 10):
568594

569595
if sys.version_info >= (3, 12):
570596
class type_param(AST):
597+
lineno: int
598+
col_offset: int
571599
end_lineno: int
572600
end_col_offset: int
573601

0 commit comments

Comments
 (0)