-
-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ast module doesn't support optional fields of Parser/Python.asdl #73808
Comments
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 bpo-29463. |
Duplicating my comment of 29463 who was in a race condition with this issue: ---- The recent change in PR 46 now change (at least) the constructor of I know the ast is autogenerated and "use at your own risk". But IPython for example, use I would be happy if it raise a deprecation warning that it will be required in the future. I'm of course speaking about Thanks. |
AST type doesn't have any information about optional fields. And I don't know it's worth enough to add it. current: if (PyTuple_GET_SIZE(args) > 0) {
if (numfields != PyTuple_GET_SIZE(args)) {
PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s"
"%zd positional argument%s",
Py_TYPE(self)->tp_name,
numfields == 0 ? "" : "either 0 or ",
numfields, numfields == 1 ? "" : "s"); will be: if (PyTuple_GET_SIZE(args) > 0) {
if (numfields > PyTuple_GET_SIZE(args)) {
PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
"%zd positional argument%s",
Py_TYPE(self)->tp_name,
numfields, numfields == 1 ? "" : "s"); |
Now trailing optional fields are optional arguments of AST type. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: