Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
492f3fc2
Commit
492f3fc2
authored
Jul 11, 2010
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow set literals in literal_eval().
parent
e40ee509
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
3 deletions
+10
-3
Doc/library/ast.rst
Doc/library/ast.rst
+5
-2
Lib/ast.py
Lib/ast.py
+2
-0
Misc/NEWS
Misc/NEWS
+3
-1
No files found.
Doc/library/ast.rst
View file @
492f3fc2
...
...
@@ -119,12 +119,15 @@ and classes for traversing abstract syntax trees:
Safely evaluate an expression node or a string containing a Python
expression. The string or node provided may only consist of the following
Python literal structures: strings, numbers, tuples, lists, dicts,
boolean
s,
and ``None``.
Python literal structures: strings, numbers, tuples, lists, dicts,
set
s,
booleans,
and ``None``.
This can be used for safely evaluating strings containing Python expressions
from untrusted sources without the need to parse the values oneself.
.. versionchanged:: 3.2
Now allows set literals.
.. function:: get_docstring(node, clean=True)
...
...
Lib/ast.py
View file @
492f3fc2
...
...
@@ -58,6 +58,8 @@ def literal_eval(node_or_string):
return
tuple
(
map
(
_convert
,
node
.
elts
))
elif
isinstance
(
node
,
List
):
return
list
(
map
(
_convert
,
node
.
elts
))
elif
isinstance
(
node
,
Set
):
return
set
(
map
(
_convert
,
node
.
elts
))
elif
isinstance
(
node
,
Dict
):
return
dict
((
_convert
(
k
),
_convert
(
v
))
for
k
,
v
in
zip
(
node
.
keys
,
node
.
values
))
...
...
Misc/NEWS
View file @
492f3fc2
...
...
@@ -470,7 +470,9 @@ C-API
Library
-------
- Issue #9164: Ensure that sysconfig handles duplicate -arch flags in CFLAGS
- ``ast.literal_eval()`` now allows set literals.
- Issue #9164: Ensure that sysconfig handles duplicate -arch flags in CFLAGS.
- Issue #7646: The fnmatch pattern cache no longer grows without bound.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment