This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author iritkatriel
Recipients BTaskaya, RJ722, benjamin.peterson, iritkatriel, larry, mdk, ncoghlan, rhettinger, serhiy.storchaka
Date 2020-09-27.12:10:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1601208640.54.0.880695229631.issue17490@roundup.psfhosted.org>
In-reply-to
Content
I think this is a bug in literal_eval:

>>> 3+6j
(3+6j)
>>> 6j+3
(3+6j)
>>> ast.literal_eval('3+6j')
(3+6j)
>>> ast.literal_eval('6j+3')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\User\src\cpython\lib\ast.py", line 105, in literal_eval
    return _convert(node_or_string)
  File "C:\Users\User\src\cpython\lib\ast.py", line 104, in _convert
    return _convert_signed_num(node)
  File "C:\Users\User\src\cpython\lib\ast.py", line 78, in _convert_signed_num
    return _convert_num(node)
  File "C:\Users\User\src\cpython\lib\ast.py", line 69, in _convert_num
    _raise_malformed_node(node)
  File "C:\Users\User\src\cpython\lib\ast.py", line 66, in _raise_malformed_node
    raise ValueError(f'malformed node or string: {node!r}')
ValueError: malformed node or string: <ast.BinOp object at 0x023D0910>


literal_eval accepts complex rhs, but not lhs: 
https://github.com/python/cpython/blame/master/Lib/ast.py#L99
if isinstance(left, (int, float)) and isinstance(right, complex):

This was introduced here, I'm not sure why:
https://github.com/python/cpython/commit/d8ac4d1d5ac256ebf3d8d38c226049abec82a2a0


In Nick's aborted patch, he removed that check.
History
Date User Action Args
2020-09-27 12:10:40iritkatrielsetrecipients: + iritkatriel, rhettinger, ncoghlan, larry, benjamin.peterson, serhiy.storchaka, mdk, RJ722, BTaskaya
2020-09-27 12:10:40iritkatrielsetmessageid: <1601208640.54.0.880695229631.issue17490@roundup.psfhosted.org>
2020-09-27 12:10:40iritkatriellinkissue17490 messages
2020-09-27 12:10:39iritkatrielcreate