[issue40000] Improve AST validation for Constant nodes

Batuhan Taskaya report at bugs.python.org
Wed Mar 18 05:46:12 EDT 2020


New submission from Batuhan Taskaya <batuhanosmantaskaya at gmail.com>:

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

----------
messages: 364505
nosy: BTaskaya
priority: normal
severity: normal
status: open
title: Improve AST validation for Constant nodes

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40000>
_______________________________________


More information about the Python-bugs-list mailing list