mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
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".
This commit is contained in:
parent
044cf94f61
commit
bace59d8b8
10 changed files with 49 additions and 22 deletions
26
Lib/ast.py
26
Lib/ast.py
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue