[issue38396] ast.literal_eval doesn't give information about node except the type of it

2019-10-07 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

I have same doubts.

See also issue32888.

--
resolution:  -> duplicate
stage: patch review -> resolved
status: open -> closed
superseder:  -> Improve exception message in ast.literal_eval

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38396] ast.literal_eval doesn't give information about node except the type of it

2019-10-07 Thread Ivan Levkivskyi


Ivan Levkivskyi  added the comment:

The downside however is that exception messages can become very long. So I am 
not sure we should change this.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38396] ast.literal_eval doesn't give information about node except the type of it

2019-10-07 Thread Batuhan


Change by Batuhan :


--
keywords: +patch
pull_requests: +16208
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/16620

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38396] ast.literal_eval doesn't give information about node except the type of it

2019-10-07 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +levkivskyi

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38396] ast.literal_eval doesn't give information about node except the type of it

2019-10-07 Thread Batuhan


New submission from Batuhan :

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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com