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 terry.reedy
Recipients georg.brandl, terry.reedy
Date 2008-10-13.23:17:33
SpamBayes Score 3.8857806e-15
Marked as misclassified No
Message-id <1223939855.4.0.779100160496.issue4118@psf.upfronthosting.co.za>
In-reply-to
Content
From docs.python.org
2.6: Compile the source into a code or AST object.
3.0: Compile the source into a code object.
Add 'or AST ' to the latter.

Both: Refer to the _ast module documentation
<there is none, docs only for the ast module, but see below>

Both: for information on how to compile into and from AST objects.

This sentence should at least have 'and from AST ' deleted. The
information on 'from' is given in the previous sentence.
Both: source can either be a string or an AST object.

The ast doc adds nothing.  "A modified abstract syntax tree can be
compiled into a Python code object using the built-in compile() function."

The remainder of the sentence could be replaced by the shorter
"To compile into an AST object, import ast and pass ast.PyCF_ONLY_AST as
a flag."

This could be followed by "See ast module documentation for more."

----
In the ast doc, both say: "An abstract syntax tree can be generated by
passing _ast.PyCF_ONLY_AST ..."

That should be ast, not _ast; the existence of the shadow C version is a
CPython implementation detail.

In the parse() doc lines, 'PyCF_ONLY_AST' should, I think, have the
'ast' prefix as the former will not work unless one does 'from ast
import PyCF_ONLY_AST' (or '... import *').

----
Back to compile():
2.6 (and before): When compiling a string with multi-line statements...
3.0 <Caveats missing>

The first, about '\n' versus '\r\n' still applies.
print (compile("def f():\r\n  pass #haha",'','exec')) #fails
print (compile("def f():\n  pass #haha",'','exec')) # succeeds

The second, at least for 2.5.2 and 3.0c1 (and I presume for 2.6), only
applies, it seems, based on testing, if the last line consists only of a
comment.  In the second example above, putting '#haha' on a separate
line fails.

See: 'compile' built-in function failures when missing EOL
http://bugs.python.org/issue1479099

I am not sure what to suggest, but a warning that is nearly always a
false alarm confuses and lulls.
History
Date User Action Args
2008-10-13 23:17:35terry.reedysetrecipients: + terry.reedy, georg.brandl
2008-10-13 23:17:35terry.reedysetmessageid: <1223939855.4.0.779100160496.issue4118@psf.upfronthosting.co.za>
2008-10-13 23:17:34terry.reedylinkissue4118 messages
2008-10-13 23:17:33terry.reedycreate