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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions stdlib/3/_ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,32 @@ class AST:
_attributes: ClassVar[typing.Tuple[str, ...]]
_fields: ClassVar[typing.Tuple[str, ...]]
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
# TODO: Not all nodes have all of the following attributes
lineno: int
col_offset: int
if sys.version_info >= (3, 8):
end_lineno: Optional[int]
end_col_offset: Optional[int]
type_comment: Optional[str]

class mod(AST):
...

if sys.version_info >= (3, 8):
class type_ignore(AST): ...

class TypeIgnore(type_ignore): ...

class FunctionType(mod):
argtypes: typing.List[expr]
returns: expr

class Module(mod):
body = ... # type: typing.List[stmt]
if sys.version_info >= (3, 7):
docstring: Optional[str]
if sys.version_info >= (3, 8):
type_ignores: typing.List[TypeIgnore]

class Interactive(mod):
body = ... # type: typing.List[stmt]
Expand Down Expand Up @@ -232,10 +248,10 @@ class Call(expr):
args = ... # type: typing.List[expr]
keywords = ... # type: typing.List[keyword]

class Num(expr):
n = ... # type: float
class Num(expr): # Deprecated in 3.8; use Constant
n = ... # type: complex

class Str(expr):
class Str(expr): # Deprecated in 3.8; use Constant
s = ... # type: str

if sys.version_info >= (3, 6):
Expand All @@ -247,12 +263,24 @@ if sys.version_info >= (3, 6):
class JoinedStr(expr):
values = ... # type: typing.List[expr]

class Bytes(expr):
class Bytes(expr): # Deprecated in 3.8; use Constant
s = ... # type: bytes

class NameConstant(expr):
value = ... # type: Any

if sys.version_info >= (3, 8):
class Constant(expr):
value: Any # None, str, bytes, bool, int, float, complex, Ellipsis
kind: Optional[str]
# Aliases for value, for backwards compatibility
s: Any
n: complex

class NamedExpr(expr):
target: expr
value: expr

class Ellipsis(expr): ...

class Attribute(expr):
Expand Down
8 changes: 7 additions & 1 deletion stdlib/3/ast.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Python 3.5 ast

import sys
# Rename typing to _typing, as not to conflict with typing imported
# from _ast below when loaded in an unorthodox way by the Dropbox
# internal Bazel integration.
Expand All @@ -17,7 +18,12 @@ class NodeTransformer(NodeVisitor):

_T = TypeVar('_T', bound=AST)

def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: str = ...) -> Module: ...
if sys.version_info >= (3, 8):
def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: str = ...,
type_comments: bool = ..., feature_version: int = ...) -> AST: ...
else:
def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: str = ...) -> AST: ...

def copy_location(new_node: _T, old_node: AST) -> _T: ...
def dump(node: AST, annotate_fields: bool = ..., include_attributes: bool = ...) -> str: ...
def fix_missing_locations(node: _T) -> _T: ...
Expand Down