From e767c38c37e29eeb8d33b84a56de136fa07afdec Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 2 Jul 2018 22:18:38 +0200 Subject: [PATCH] Move lineno and col_offset to ast.AST (#2298) Also, mark AST._attributes and _fields as class vars. `lineno` and `col_offset` were previously defined on a few sub-classes of `AST`, e.g. `expr`, even though https://docs.python.org/3/library/ast.html explicitly states that `AST` has these two attributes. These attributes are only present if they were supplied as arguments to the constructor, but the same is true for the subclasses. --- stdlib/3/_ast.pyi | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/stdlib/3/_ast.pyi b/stdlib/3/_ast.pyi index 4b3de95ed..07e96eb75 100644 --- a/stdlib/3/_ast.pyi +++ b/stdlib/3/_ast.pyi @@ -1,15 +1,17 @@ import sys import typing -from typing import Any, Optional, Union +from typing import Any, Optional, Union, ClassVar PyCF_ONLY_AST = ... # type: int _identifier = str class AST: - _attributes = ... # type: typing.Tuple[str, ...] - _fields = ... # type: typing.Tuple[str, ...] + _attributes: ClassVar[typing.Tuple[str, ...]] + _fields: ClassVar[typing.Tuple[str, ...]] def __init__(self, *args: Any, **kwargs: Any) -> None: ... + lineno: int + col_offset: int class mod(AST): ... @@ -29,9 +31,7 @@ class Suite(mod): body = ... # type: typing.List[stmt] -class stmt(AST): - lineno = ... # type: int - col_offset = ... # type: int +class stmt(AST): ... class FunctionDef(stmt): name = ... # type: _identifier @@ -165,9 +165,7 @@ class Index(slice): value = ... # type: expr -class expr(AST): - lineno = ... # type: int - col_offset = ... # type: int +class expr(AST): ... class BoolOp(expr): op = ... # type: boolop @@ -353,8 +351,6 @@ class ExceptHandler(AST): type = ... # type: Optional[expr] name = ... # type: Optional[_identifier] body = ... # type: typing.List[stmt] - lineno = ... # type: int - col_offset = ... # type: int class arguments(AST): @@ -368,8 +364,6 @@ class arguments(AST): class arg(AST): arg = ... # type: _identifier annotation = ... # type: Optional[expr] - lineno = ... # type: int - col_offset = ... # type: int class keyword(AST): arg = ... # type: Optional[_identifier]