Merged revisions 62004 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r62004 | georg.brandl | 2008-03-28 13:11:56 +0100 (Fr, 28 Mär 2008) | 4 lines
Patch #1810 by Thomas Lee, reviewed by myself:
allow compiling Python AST objects into code objects
in compile().
........
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index 7c97edb..d1e979c 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -193,21 +193,21 @@
.. function:: compile(source, filename, mode[, flags[, dont_inherit]])
- Compile the *source* into a code object. Code objects can be executed by a call
- to :func:`exec` or evaluated by a call to :func:`eval`. 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 commonly used). The *mode*
- argument specifies what kind of code must be compiled; it can be ``'exec'`` if
- *source* consists of a sequence of statements, ``'eval'`` if it consists of a
- single expression, or ``'single'`` if it consists of a single interactive
- statement (in the latter case, expression statements that evaluate to something
- else than ``None`` will be printed).
+ Compile the *source* into a code object. Code objects can be
+ executed by a call to :func:`exec` or evaluated by a call to
+ :func:`eval`. *source* can either be a string or an AST object.
+ Refer to the :mod:`_ast` module documentation for information on
+ how to compile into and from AST objects.
- When compiling multi-line statements, two caveats apply: line endings must be
- represented by a single newline character (``'\n'``), and the input must be
- terminated by at least one newline character. If line endings are represented
- by ``'\r\n'``, use the string :meth:`replace` method to change them into
- ``'\n'``.
+ 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 commonly used). The *mode*
+ argument specifies what kind of code must be compiled; it can be
+ ``'exec'`` if *source* consists of a sequence of statements,
+ ``'eval'`` if it consists of a single expression, or ``'single'``
+ if it consists of a single interactive statement (in the latter
+ case, expression statements that evaluate to something else than
+ ``None`` will be printed).
The optional arguments *flags* and *dont_inherit* (which are new in Python 2.2)
control which future statements (see :pep:`236`) affect the compilation of
@@ -227,6 +227,9 @@
This function raises :exc:`SyntaxError` if the compiled source is invalid,
and :exc:`TypeError` if the source contains null bytes.
+ .. versionadded:: 2.6
+ Support for compiling AST objects.
+
.. function:: complex([real[, imag]])