You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ast.literal_eval doesn't give information about node except the type of it #82577
bpo-32888: Improve exception message in ast.literal_eval
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2019-10-07.19:47:55.659>created_at=<Date2019-10-07.15:55:56.849>labels= ['library', '3.9']
title="ast.literal_eval doesn't give information about node except the type of it"updated_at=<Date2019-10-07.19:47:55.658>user='https://github.com/isidentical'
def_convert_num(node):
ifisinstance(node, Constant):
iftype(node.value) in (int, float, complex):
returnnode.value>raiseValueError('malformed node or string: '+repr(node))
EValueError: malformednodeorstring: <_ast.Nameobjectat0x7f0e7ebab320>
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):
ifisinstance(node, Constant):
iftype(node.value) in (int, float, complex):
returnnode.value>raiseValueError('malformed node or string: '+dump(node))
EValueError: malformednodeorstring: Name(id='a', ctx=Load())
Activity
isidentical commentedon Oct 7, 2019
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>
ilevkivskyi commentedon Oct 7, 2019
The downside however is that exception messages can become very long. So I am not sure we should change this.
serhiy-storchaka commentedon Oct 7, 2019
I have same doubts.
See also bpo-32888.