[issue41631] _ast module: get_global_ast_state() doesn't work with Mercurial lazy import

STINNER Victor report at bugs.python.org
Thu Sep 10 09:55:18 EDT 2020


STINNER Victor <vstinner at python.org> added the comment:

About subinterpreters. In Python 3.8, _ast.AST type is a static type:

static PyTypeObject AST_type = {...};

In Python 3.9, it's now a heap type:

static PyType_Spec AST_type_spec = {...};
state->AST_type = PyType_FromSpec(&AST_type_spec);

In Python 3.8, the same _ast.AST type was shared by all interpreters. With my PR 21961, the _ast.AST type is a heap type but it is also shared by all interpreters.

Compared to Python 3.8, PR 21961 has no regression related to subinterpreters. It's not better nor worse. The minor benefit is that _ast.AST is cleared at Python exit (see _PyAST_Fini()).

While I would be nice to make _ast.AST per interpreter, it would be an *enhancement*. I consider that it can wait for Python 3.10.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41631>
_______________________________________


More information about the Python-bugs-list mailing list