[issue29622] ast module doesn't support optional fields of Parser/Python.asdl

STINNER Victor report at bugs.python.org
Wed Feb 22 11:48:32 EST 2017


New submission from STINNER Victor:

The _ast.AST constructor requires a tuple with the same number of items than the fields list.

Example with Raise:

ASDL: Raise(expr? exc, expr? cause)

>>> import _ast
>>> _ast.Raise()
<_ast.Raise object at 0x7fc2ca7dee90>
>>> _ast.Raise(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Raise constructor takes either 0 or 2 positional arguments
>>> _ast.Raise(1, 2)
<_ast.Raise object at 0x7fc2ca7def60>

The cause field is optional in the ASDL, but required in the _ast module.

A tradeoff would be to add the minimum and maximum number of fields to _ast.AST.

This issue should prevent API breakage caused by the new docstring attribute added by issue #29463.

----------
messages: 288372
nosy: haypo, inada.naoki
priority: normal
severity: normal
status: open
title: ast module doesn't support optional fields of Parser/Python.asdl
type: enhancement
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29622>
_______________________________________


More information about the Python-bugs-list mailing list