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.

classification
Title: Glitch in eval() doc
Type: Stage:
Components: Documentation Versions: Python 3.0, Python 2.6, Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, terry.reedy
Priority: normal Keywords:

Created on 2008-08-16 20:39 by terry.reedy, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg71235 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2008-08-16 20:39
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.
msg72192 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-08-30 12:47
Fixed in r66065.
History
Date User Action Args
2022-04-11 14:56:37adminsetgithub: 47819
2008-08-30 12:47:17georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg72192
2008-08-16 20:39:47terry.reedycreate