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.

Unsupported provider

classification
Title: ast.literal_eval does not handled new set literals
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.1
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: aronacher, benjamin.peterson, eric.araujo, ezio.melotti, georg.brandl, gpolo, mark.dickinson, nestor, piotr.dobrogost, rhettinger, terry.reedy
Priority: normal Keywords:

Created on 2010-10-13 19:36 by nestor, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (7)
msg118568 - (view) Author: nestor (nestor) Date: 2010-10-13 19:36
>>> import ast
>>> eval('{1:11,2:22}')
{1: 11, 2: 22}
>>> ast.literal_eval('{1:11,2:22}')
{1: 11, 2: 22}

>>> eval('{1,2}')
{1, 2}
>>> ast.literal_eval('{1,2}')
Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    ast.literal_eval('{1,2}')
  File "C:\Python31\lib\ast.py", line 80, in literal_eval
    return _convert(node_or_string)
  File "C:\Python31\lib\ast.py", line 79, in _convert
    raise ValueError('malformed string')
ValueError: malformed string

>>> 

I haven't tested for 2.7 or 3.2 but this bug probably applies also there.
msg118571 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-10-13 19:58
This is fixed in 3.2 (see r82804).  As it is a new feature, it is not backported to 2.7 or earlier.
msg119054 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-10-18 18:14
Set literals, a new feature indeed, have been backported to 2.7 and 3.1.  The lack of support in ast.literal_eval is arguably a bug.  Benjamin, can you make a statement as release manager?  Thanks.
msg119064 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-10-18 18:55
2010/10/18 Éric Araujo <report@bugs.python.org>:
>
> Éric Araujo <merwok@netwok.org> added the comment:
>
> Set literals, a new feature indeed, have been backported to 2.7 and 3.1.  The lack of support in ast.literal_eval is arguably a bug.  Benjamin, can you make a statement as release manager?  Thanks.

No change please.
msg119071 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-10-18 19:33
ast.literal_eval's docs: 

'The string or node provided may only consist of the following Python literal structures: strings, numbers, tuples, lists, dicts, booleans, and None.'
msg119094 - (view) Author: nestor (nestor) Date: 2010-10-18 23:39
FYI although it breaks symmetry with eval, I am fine with this going in for 3.2. It just surprised me and I wanted to make sure it was documented here for future reference.
msg166055 - (view) Author: Piotr Dobrogost (piotr.dobrogost) Date: 2012-07-21 19:52
I totally agree with Eric's statement that "Set literals, a new feature indeed, have been backported to 2.7 and 3.1.  The lack of support in ast.literal_eval is arguably a bug."
I came here from "set literal syntax support in Python 2.7" question at Stackoverflow (http://stackoverflow.com/q/6078262/95735)
History
Date User Action Args
2022-04-11 14:57:07adminsetgithub: 54300
2012-07-21 19:52:38piotr.dobrogostsetnosy: + piotr.dobrogost
messages: + msg166055
2011-12-06 01:47:59benjamin.petersonlinkissue13536 superseder
2010-10-18 23:39:29nestorsetmessages: + msg119094
2010-10-18 19:33:44rhettingersetresolution: out of date -> not a bug
messages: + msg119071
2010-10-18 18:55:46benjamin.petersonsetmessages: + msg119064
2010-10-18 18:14:42eric.araujosetnosy: + eric.araujo
messages: + msg119054
2010-10-13 19:58:00georg.brandlsetstatus: open -> closed
resolution: out of date
messages: + msg118571
2010-10-13 19:39:49ezio.melottisetnosy: + ezio.melotti
2010-10-13 19:36:40nestorcreate