classification
Title: _ast.ast_type_init does not handle args and kwargs correctly.
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, brett.cannon, miss-islington, pablogsal, remi.lapeyre, serhiy.storchaka, yselivanov
Priority: normal Keywords: patch

Created on 2019-03-14 14:47 by remi.lapeyre, last changed 2020-05-24 21:32 by miss-islington. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 12382 merged remi.lapeyre, 2019-03-17 18:03
PR 20365 merged miss-islington, 2020-05-24 21:13
PR 20366 merged miss-islington, 2020-05-24 21:13
Messages (4)
msg337926 - (view) Author: Rémi Lapeyre (remi.lapeyre) * Date: 2019-03-14 14:47
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.
msg369829 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-05-24 21:13
New changeset c73914a562580ae72048876cb42ed8e76e2c83f9 by Rémi Lapeyre in branch 'master':
bpo-36290: Fix keytword collision handling in AST node constructors (GH-12382)
https://github.com/python/cpython/commit/c73914a562580ae72048876cb42ed8e76e2c83f9
msg369831 - (view) Author: miss-islington (miss-islington) Date: 2020-05-24 21:31
New changeset 907ee1f14aaf587683ced44818c5a1d1cabf4174 by Miss Islington (bot) in branch '3.8':
bpo-36290: Fix keytword collision handling in AST node constructors (GH-12382)
https://github.com/python/cpython/commit/907ee1f14aaf587683ced44818c5a1d1cabf4174
msg369832 - (view) Author: miss-islington (miss-islington) Date: 2020-05-24 21:32
New changeset 1a4e9e6f35dad26b37639198f1444591d04399e0 by Miss Islington (bot) in branch '3.9':
bpo-36290: Fix keytword collision handling in AST node constructors (GH-12382)
https://github.com/python/cpython/commit/1a4e9e6f35dad26b37639198f1444591d04399e0
History
Date User Action Args
2020-05-24 21:32:35miss-islingtonsetmessages: + msg369832
2020-05-24 21:31:51miss-islingtonsetmessages: + msg369831
2020-05-24 21:16:59pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-05-24 21:13:21miss-islingtonsetpull_requests: + pull_request19630
2020-05-24 21:13:13miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request19629
2020-05-24 21:13:00pablogsalsetnosy: + pablogsal
messages: + msg369829
2019-03-17 18:03:42remi.lapeyresetkeywords: + patch
stage: patch review
pull_requests: + pull_request12340
2019-03-15 19:13:57brett.cannonsetnosy: + brett.cannon, benjamin.peterson, serhiy.storchaka, yselivanov
2019-03-14 14:47:19remi.lapeyrecreate