mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
bpo-41631: _ast module uses again a global state (#21961)
Partially revert commit ac46eb4ad6
:
"bpo-38113: Update the Python-ast.c generator to PEP384 (gh-15957)".
Using a module state per module instance is causing subtle practical
problems.
For example, the Mercurial project replaces the __import__() function
to implement lazy import, whereas Python expected that "import _ast"
always return a fully initialized _ast module.
Add _PyAST_Fini() to clear the state at exit.
The _ast module has no state (set _astmodule.m_size to 0). Remove
astmodule_traverse(), astmodule_clear() and astmodule_free()
functions.
This commit is contained in:
parent
7bcc6456ad
commit
e5fbe0cbd4
7 changed files with 162 additions and 311 deletions
37
Lib/ast.py
37
Lib/ast.py
|
@ -497,18 +497,20 @@ class NodeTransformer(NodeVisitor):
|
|||
return node
|
||||
|
||||
|
||||
# The following code is for backward compatibility.
|
||||
# It will be removed in future.
|
||||
# If the ast module is loaded more than once, only add deprecated methods once
|
||||
if not hasattr(Constant, 'n'):
|
||||
# The following code is for backward compatibility.
|
||||
# It will be removed in future.
|
||||
|
||||
def _getter(self):
|
||||
"""Deprecated. Use value instead."""
|
||||
return self.value
|
||||
def _getter(self):
|
||||
"""Deprecated. Use value instead."""
|
||||
return self.value
|
||||
|
||||
def _setter(self, value):
|
||||
self.value = value
|
||||
def _setter(self, value):
|
||||
self.value = value
|
||||
|
||||
Constant.n = property(_getter, _setter)
|
||||
Constant.s = property(_getter, _setter)
|
||||
Constant.n = property(_getter, _setter)
|
||||
Constant.s = property(_getter, _setter)
|
||||
|
||||
class _ABC(type):
|
||||
|
||||
|
@ -600,14 +602,19 @@ class ExtSlice(slice):
|
|||
def __new__(cls, dims=(), **kwargs):
|
||||
return Tuple(list(dims), Load(), **kwargs)
|
||||
|
||||
def _dims_getter(self):
|
||||
"""Deprecated. Use elts instead."""
|
||||
return self.elts
|
||||
# If the ast module is loaded more than once, only add deprecated methods once
|
||||
if not hasattr(Tuple, 'dims'):
|
||||
# The following code is for backward compatibility.
|
||||
# It will be removed in future.
|
||||
|
||||
def _dims_setter(self, value):
|
||||
self.elts = value
|
||||
def _dims_getter(self):
|
||||
"""Deprecated. Use elts instead."""
|
||||
return self.elts
|
||||
|
||||
Tuple.dims = property(_dims_getter, _dims_setter)
|
||||
def _dims_setter(self, value):
|
||||
self.elts = value
|
||||
|
||||
Tuple.dims = property(_dims_getter, _dims_setter)
|
||||
|
||||
class Suite(mod):
|
||||
"""Deprecated AST node class. Unused in Python 3."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue