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

2017-03-24 Thread INADA Naoki

INADA Naoki added the comment:


New changeset 4c78c527d215c37472145152cb0e95f196cdddc9 by INADA Naoki in branch 
'master':
bpo-29622: Make AST constructor to accept less than enough number of positional 
arguments (GH-249)
https://github.com/python/cpython/commit/4c78c527d215c37472145152cb0e95f196cdddc9


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2017-02-23 Thread Matthias Bussonnier

Changes by Matthias Bussonnier :


--
pull_requests: +240

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2017-02-23 Thread INADA Naoki

Changes by INADA Naoki :


--
resolution:  -> fixed
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2017-02-23 Thread INADA Naoki

INADA Naoki added the comment:

@mbussonn With PR 249, "import os" and "%timeit" works fine.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2017-02-23 Thread INADA Naoki

INADA Naoki added the comment:

Now trailing optional fields are optional arguments of AST type.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2017-02-23 Thread INADA Naoki

Changes by INADA Naoki :


--
pull_requests: +216

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2017-02-22 Thread INADA Naoki

INADA Naoki added the comment:

AST type doesn't have any information about optional fields.  And I don't know 
it's worth enough to add it.
When AST is instantiated by keyword arguments, there are no check about absence 
of some fields.
I suppose we can just loosen positional arguments too.

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");

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2017-02-22 Thread Thomas Kluyver

Changes by Thomas Kluyver :


--
nosy: +takluyver

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2017-02-22 Thread Matthias Bussonnier

Matthias Bussonnier added the comment:

Duplicating my comment of 29463 who was in a race condition with this issue:


thank you for your work on the AST, I know many developers are looking forward 
to improvement and stabilisation with the hope of having it stable (and 
documented) in the stdlib at some point. 

The recent change in PR 46 now change (at least) the constructor of 
`ast.Module` to take a second mandatory parameter (the docstring). 

I know the ast is autogenerated and "use at your own risk". But IPython for 
example, use `mod = ast.Module([nodes])`, with the second mandatory parameter 
added to Module that make it incompatible with current Python 3.7. 
Well it's long until it's released, and we can patch things, but I'm sure we 
are not the only one in this case, and we'd like older version of IPython to 
still be compatible with Python 3.7, so if  `Module()`'s second parameter (the 
docstring) could be optional, that would be great. 

I would be happy if it raise a deprecation warning that it will be required in 
the future.

I'm of course speaking about `Module` because that's the first error I 
encountered, but I'm guessing it applies to other changed AST nodes. 

Thanks.
---

--
nosy: +mbussonn

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2017-02-22 Thread STINNER Victor

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 "", line 1, in 
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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com