Commit b44c8619 authored by Benjamin Peterson's avatar Benjamin Peterson

document that various functions that parse from source will interpret things...

document that various functions that parse from source will interpret things as latin-1 (closes #18870)
parent 71b2ded0
...@@ -131,10 +131,10 @@ and classes for traversing abstract syntax trees: ...@@ -131,10 +131,10 @@ and classes for traversing abstract syntax trees:
.. function:: literal_eval(node_or_string) .. function:: literal_eval(node_or_string)
Safely evaluate an expression node or a string containing a Python Safely evaluate an expression node or a Unicode or *Latin-1* encoded string
expression. The string or node provided may only consist of the following containing a Python expression. The string or node provided may only consist
Python literal structures: strings, numbers, tuples, lists, dicts, booleans, of the following Python literal structures: strings, numbers, tuples, lists,
and ``None``. dicts, booleans, and ``None``.
This can be used for safely evaluating strings containing Python expressions This can be used for safely evaluating strings containing Python expressions
from untrusted sources without the need to parse the values oneself. from untrusted sources without the need to parse the values oneself.
......
...@@ -199,8 +199,10 @@ available. They are listed here in alphabetical order. ...@@ -199,8 +199,10 @@ available. They are listed here in alphabetical order.
Compile the *source* into a code or AST object. Code objects can be executed Compile the *source* into a code or AST object. Code objects can be executed
by an :keyword:`exec` statement or evaluated by a call to :func:`eval`. by an :keyword:`exec` statement or evaluated by a call to :func:`eval`.
*source* can either be a string or an AST object. Refer to the :mod:`ast` *source* can either be a Unicode string, a *Latin-1* encoded string or an
module documentation for information on how to work with AST objects. AST object.
Refer to the :mod:`ast` module documentation for information on how to work
with AST objects.
The *filename* argument should give the file from which the code was read; The *filename* argument should give the file from which the code was read;
pass some recognizable value if it wasn't read from a file (``'<string>'`` is pass some recognizable value if it wasn't read from a file (``'<string>'`` is
...@@ -388,9 +390,9 @@ available. They are listed here in alphabetical order. ...@@ -388,9 +390,9 @@ available. They are listed here in alphabetical order.
.. function:: eval(expression[, globals[, locals]]) .. function:: eval(expression[, globals[, locals]])
The arguments are a string and optional globals and locals. If provided, The arguments are a Unicode or *Latin-1* encoded string and optional
*globals* must be a dictionary. If provided, *locals* can be any mapping globals and locals. If provided, *globals* must be a dictionary.
object. If provided, *locals* can be any mapping object.
.. versionchanged:: 2.4 .. versionchanged:: 2.4
formerly *locals* was required to be a dictionary. formerly *locals* was required to be a dictionary.
......
...@@ -981,15 +981,16 @@ The :keyword:`exec` statement ...@@ -981,15 +981,16 @@ The :keyword:`exec` statement
exec_stmt: "exec" `or_expr` ["in" `expression` ["," `expression`]] exec_stmt: "exec" `or_expr` ["in" `expression` ["," `expression`]]
This statement supports dynamic execution of Python code. The first expression This statement supports dynamic execution of Python code. The first expression
should evaluate to either a string, an open file object, a code object, or a should evaluate to either a Unicode string, a *Latin-1* encoded string, an open
tuple. If it is a string, the string is parsed as a suite of Python statements file object, a code object, or a tuple. If it is a string, the string is parsed
which is then executed (unless a syntax error occurs). [#]_ If it is an open as a suite of Python statements which is then executed (unless a syntax error
file, the file is parsed until EOF and executed. If it is a code object, it is occurs). [#]_ If it is an open file, the file is parsed until EOF and executed.
simply executed. For the interpretation of a tuple, see below. In all cases, If it is a code object, it is simply executed. For the interpretation of a
the code that's executed is expected to be valid as file input (see section tuple, see below. In all cases, the code that's executed is expected to be
:ref:`file-input`). Be aware that the :keyword:`return` and :keyword:`yield` valid as file input (see section :ref:`file-input`). Be aware that the
statements may not be used outside of function definitions even within the :keyword:`return` and :keyword:`yield` statements may not be used outside of
context of code passed to the :keyword:`exec` statement. function definitions even within the context of code passed to the
:keyword:`exec` statement.
In all cases, if the optional parts are omitted, the code is executed in the In all cases, if the optional parts are omitted, the code is executed in the
current scope. If only the first expression after ``in`` is specified, current scope. If only the first expression after ``in`` is specified,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment