[issue38396] ast.literal_eval doesn't give information about node except the type of it
Batuhan
report at bugs.python.org
Mon Oct 7 11:55:56 EDT 2019
New submission from Batuhan <batuhanosmantaskaya at gmail.com>:
def _convert_num(node):
if isinstance(node, Constant):
if type(node.value) in (int, float, complex):
return node.value
> raise ValueError('malformed node or string: ' + repr(node))
E ValueError: malformed node or string: <_ast.Name object at 0x7f0e7ebab320>
When a malformed node passes into literal_eval, it raises ValueError with repr of node (which is just a memory address and type). I think using dump(node) at there is a better option, like
node = <_ast.Name object at 0x7fa8279847d0>
def _convert_num(node):
if isinstance(node, Constant):
if type(node.value) in (int, float, complex):
return node.value
> raise ValueError('malformed node or string: ' + dump(node))
E ValueError: malformed node or string: Name(id='a', ctx=Load())
----------
components: Library (Lib)
messages: 354103
nosy: BTaskaya
priority: normal
severity: normal
status: open
title: ast.literal_eval doesn't give information about node except the type of it
versions: Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38396>
_______________________________________
More information about the Python-bugs-list
mailing list