[issue32888] Improve exception message in ast.literal_eval

2019-12-19 Thread Batuhan


Change by Batuhan :


--
pull_requests: +17130
pull_request: https://github.com/python/cpython/pull/17662

___
Python tracker 

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



[issue32888] Improve exception message in ast.literal_eval

2019-12-14 Thread Batuhan


Change by Batuhan :


--
pull_requests: +17076
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



[issue32888] Improve exception message in ast.literal_eval

2018-07-03 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Please wait until issue32892 and issue32893 be committed or rejected before 
merging this PR.

--
dependencies: +Remove specific constant AST types in favor of ast.Constant, 
ast.literal_eval() shouldn't accept booleans as numbers in AST
nosy: +brian.curtin

___
Python tracker 

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



[issue32888] Improve exception message in ast.literal_eval

2018-02-24 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
pull_requests:  -

___
Python tracker 

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



[issue32888] Improve exception message in ast.literal_eval

2018-02-20 Thread Chris Angelico

Chris Angelico  added the comment:

(BTW, by "proposed" I mean that the change that I describe is in the PR.)

--

___
Python tracker 

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



[issue32888] Improve exception message in ast.literal_eval

2018-02-20 Thread Chris Angelico

Chris Angelico  added the comment:

Actually, it's a bit more complicated than I thought. Current proposed 
solution: Track the context of each conversion, thus allowing different errors 
to be distinguished.

--

___
Python tracker 

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



[issue32888] Improve exception message in ast.literal_eval

2018-02-20 Thread Chris Angelico

Chris Angelico  added the comment:

Hmm, I think I see what I broke there. It was part of the merge conflict 
resolution - I moved the check into the function, which is actually incorrect. 
It wasn't misleading like that in the original patch. Will fix that.

--

___
Python tracker 

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



[issue32888] Improve exception message in ast.literal_eval

2018-02-20 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

I afraid this makes an error message more confusing and misleading.

>>> ast.literal_eval('~2')
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/serhiy/py/cpython/Lib/ast.py", line 93, in literal_eval
return _convert(node_or_string)
  File "/home/serhiy/py/cpython/Lib/ast.py", line 92, in _convert
return _convert_signed_num(node)
  File "/home/serhiy/py/cpython/Lib/ast.py", line 65, in _convert_signed_num
return _convert_num(node)
  File "/home/serhiy/py/cpython/Lib/ast.py", line 56, in _convert_num
raise ValueError('%s not allowed in literal' % type(node).__name__)
ValueError: UnaryOp not allowed in literal

This is not true since + and - are allowed:

>>> ast.literal_eval('-2')
-2

>>> ast.literal_eval('2+3')
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/serhiy/py/cpython/Lib/ast.py", line 93, in literal_eval
return _convert(node_or_string)
  File "/home/serhiy/py/cpython/Lib/ast.py", line 92, in _convert
return _convert_signed_num(node)
  File "/home/serhiy/py/cpython/Lib/ast.py", line 65, in _convert_signed_num
return _convert_num(node)
  File "/home/serhiy/py/cpython/Lib/ast.py", line 56, in _convert_num
raise ValueError('%s not allowed in literal' % type(node).__name__)
ValueError: BinOp not allowed in literal

But:

>>> ast.literal_eval('2+3j')
(2+3j)

>>> ast.literal_eval('"a"+"b"')
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/serhiy/py/cpython/Lib/ast.py", line 93, in literal_eval
return _convert(node_or_string)
  File "/home/serhiy/py/cpython/Lib/ast.py", line 85, in _convert
left = _convert_signed_num(node.left)
  File "/home/serhiy/py/cpython/Lib/ast.py", line 65, in _convert_signed_num
return _convert_num(node)
  File "/home/serhiy/py/cpython/Lib/ast.py", line 56, in _convert_num
raise ValueError('%s not allowed in literal' % type(node).__name__)
ValueError: Str not allowed in literal

But Str is allowed:

>>> ast.literal_eval('"ab"')
'ab'

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue32888] Improve exception message in ast.literal_eval

2018-02-20 Thread Chris Angelico

Change by Chris Angelico :


--
keywords: +patch
pull_requests: +5558
stage:  -> patch review

___
Python tracker 

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



[issue32888] Improve exception message in ast.literal_eval

2018-02-20 Thread Chris Angelico

New submission from Chris Angelico :

When a non-literal is given to literal_eval, attempt to be more
helpful with the message, rather than calling it 'malformed'.

--
components: Library (Lib)
messages: 312423
nosy: Rosuav
priority: normal
pull_requests: 
severity: normal
status: open
title: Improve exception message in ast.literal_eval
versions: Python 3.8

___
Python tracker 

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