[New-bugs-announce] [issue3569] Glitch in eval() doc

Terry J. Reedy report at bugs.python.org
Sat Aug 16 22:39:47 CEST 2008


New submission from Terry J. Reedy <tjreedy at udel.edu>:

LibRef/built-in functions/eval() has this section

This function can also be used to execute arbitrary code objects (such
as those created by compile()).
In this case pass a code object instead of a string.
The code object must have been compiled passing 'eval' as the kind argument.

As pointed out by Patrick Maupin on py-dev today, the first and third
statements are contradictory: 'arbitrary' != 'limited to kind "eval"'
and the third is wrong in 2.5.  It is still wrong in 3.0b2:

>>> eval(compile('1+2', '', 'eval'))
3
>>> eval(compile('1+2', '', 'exec')) # runs and returns None

Because of the first line, I assume this is intended.

Patrick suggests that the third line be expanded to

In order to return a result other than None to eval's caller,  the code
object must have been compiled passing 'eval' as the kind argument.

I prefer the slightly more compact

In order for eval to return a result other than None, the code object
must have been compiled passing 'eval' as the kind argument.

or even

However eval will return None unless the code object was compiled with
'eval' as the kind argument.

----------
assignee: georg.brandl
components: Documentation
messages: 71235
nosy: georg.brandl, tjreedy
severity: normal
status: open
title: Glitch in eval() doc
versions: Python 2.5, Python 2.6, Python 3.0

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3569>
_______________________________________


More information about the New-bugs-announce mailing list