Author remi.lapeyre
Recipients remi.lapeyre
Date 2019-03-14.14:47:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1552574839.1.0.4927355759.issue36290@roundup.psfhosted.org>
In-reply-to
Content
While looking at issue 36287 I noticed that the argument parsing logic in _ast.ast_type_init is wrong, for example ast.Constant takes only one argument:

✗ ./python.exe 
Python 3.8.0a2+ (remotes/origin/HEAD-1-ged9b774cf3:ed9b774cf3, Mar 14 2019, 00:50:47) 
[Clang 10.0.0 (clang-1000.10.44.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> ast.Constant(1, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Constant constructor takes at most 1 positional argument
>>> ast.Constant(1)
<_ast.Constant object at 0x105b52950>
>>> ast.Constant(value=2)
<_ast.Constant object at 0x105b528f0>
>>> ast.Constant(1, value=2)
<_ast.Constant object at 0x105b529b0>
>>> ast.Constant(1, value=2).value
2


The last lines should have raised TypeError. I could reproduce the issue with Python 2.7, 3.7 and 3.8 but I'm not sure it's worth fixing for 2.7.

I will write a patch to fix the issue.
History
Date User Action Args
2019-03-14 14:47:19remi.lapeyresetrecipients: + remi.lapeyre
2019-03-14 14:47:19remi.lapeyresetmessageid: <1552574839.1.0.4927355759.issue36290@roundup.psfhosted.org>
2019-03-14 14:47:19remi.lapeyrelinkissue36290 messages
2019-03-14 14:47:18remi.lapeyrecreate