This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Improve AST validation for Constant nodes
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: BTaskaya Nosy List: BTaskaya, pablogsal, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2020-03-18 09:46 by BTaskaya, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19055 merged BTaskaya, 2020-03-18 09:56
Messages (6)
msg364505 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2020-03-18 09:46
When something that isn't constant found in a ast.Constant node's body, python reports errors like this

>>> e = ast.Expression(body=ast.Constant(value=type))
>>> ast.fix_missing_locations(e)
<_ast.Expression object at 0x7fc2c23981c0>
>>> compile(e, "<test>", "eval")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: got an invalid type in Constant: type

But if something is part of constant tuple and frozenset isn't constant, the error reporting is wrong 

>>> e = ast.Expression(body=ast.Constant(value=(1,2,type)))
>>> compile(e, "<test>", "eval")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: got an invalid type in Constant: tuple

This should've been 

TypeError: got an invalid type in Constant: type
msg364509 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-03-18 10:07
You got an anniversary issue!
msg364529 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-18 15:49
Congratulations Batuhan! You win with the bug number 40000! A nice number ;-) To be honest, I wanted to get it, but I didn't want to cheat by opening a stupid issue.
msg364530 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2020-03-18 16:02
sorry to take it Victor, maybe you can get the perfect issue number when we migrate to github?
msg364599 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-03-19 11:32
New changeset 0ac59f93c0e3f91fd994d7245578cce65654fb22 by Batuhan Taşkaya in branch 'master':
bpo-40000: Improve error messages when validating invalid ast.Constant nodes (GH-19055)
msg364626 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-19 18:43
> _PyType_Name(Py_TYPE(value)))

Why truncating the type name in the error message? The qualified name (don't call _PyType_Name()) should provide more information, no?
Date User Action Args
2022-04-11 14:59:28adminsetgithub: 84181
2020-03-19 18:43:55vstinnersetmessages: + msg364626
2020-03-19 12:01:11BTaskayasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-03-19 11:32:51pablogsalsetnosy: + pablogsal
messages: + msg364599
2020-03-18 16:02:42BTaskayasetmessages: + msg364530
2020-03-18 15:49:39vstinnersetnosy: + vstinner
messages: + msg364529
2020-03-18 10:07:02serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg364509
2020-03-18 09:56:54BTaskayasetkeywords: + patch
stage: patch review
pull_requests: + pull_request18407
2020-03-18 09:47:08BTaskayasetassignee: BTaskaya
type: enhancement
components: + Library (Lib)
versions: + Python 3.9
2020-03-18 09:46:11BTaskayacreate