diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-03-22 18:33:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-22 18:33:34 (GMT) |
commit | bace59d8b8e38f5c779ff6296ebdc0527f6db14a (patch) | |
tree | 81aa39edc1e15004da1d54507484609ab0745e22 /Lib/ast.py | |
parent | 044cf94f610e831464a69a8e713dad89878824ce (diff) | |
download | cpython-bace59d8b8e38f5c779ff6296ebdc0527f6db14a.zip cpython-bace59d8b8e38f5c779ff6296ebdc0527f6db14a.tar.gz cpython-bace59d8b8e38f5c779ff6296ebdc0527f6db14a.tar.bz2 |
bpo-39999: Improve compatibility of the ast module. (GH-19056)
* Re-add removed classes Suite, slice, Param, AugLoad and AugStore.
* Add docstrings for dummy classes.
* Add docstrings for attribute aliases.
* Set __module__ to "ast" instead of "_ast".
Diffstat (limited to 'Lib/ast.py')
-rw-r--r-- | Lib/ast.py | 26 |
1 files changed, 24 insertions, 2 deletions
@@ -489,6 +489,7 @@ class NodeTransformer(NodeVisitor): # It will be removed in future. def _getter(self): + """Deprecated. Use value instead.""" return self.value def _setter(self, value): @@ -499,6 +500,9 @@ Constant.s = property(_getter, _setter) class _ABC(type): + def __init__(cls, *args): + cls.__doc__ = """Deprecated AST node class. Use ast.Constant instead""" + def __instancecheck__(cls, inst): if not isinstance(inst, Constant): return False @@ -564,15 +568,21 @@ _const_node_type_names = { type(...): 'Ellipsis', } -class Index(AST): +class slice(AST): + """Deprecated AST node class.""" + +class Index(slice): + """Deprecated AST node class. Use the index value directly instead.""" def __new__(cls, value, **kwargs): return value -class ExtSlice(AST): +class ExtSlice(slice): + """Deprecated AST node class. Use ast.Tuple instead.""" def __new__(cls, dims=(), **kwargs): return Tuple(list(dims), Load(), **kwargs) def _dims_getter(self): + """Deprecated. Use elts instead.""" return self.elts def _dims_setter(self, value): @@ -580,6 +590,18 @@ def _dims_setter(self, value): Tuple.dims = property(_dims_getter, _dims_setter) +class Suite(mod): + """Deprecated AST node class. Unused in Python 3.""" + +class AugLoad(expr_context): + """Deprecated AST node class. Unused in Python 3.""" + +class AugStore(expr_context): + """Deprecated AST node class. Unused in Python 3.""" + +class Param(expr_context): + """Deprecated AST node class. Unused in Python 3.""" + # Large float and imaginary literals get turned into infinities in the AST. # We unparse those infinities to INFSTR. |