Issue 3569: Glitch in eval() doc (original) (raw)

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.