[Python-Dev] Passing compile(...,'exec') code to 'eval'

Armin Rigo arigo at tunes.org
Thu May 6 04:51:16 EDT 2004


Hello Brett,

On Wed, May 05, 2004 at 11:23:16AM -0700, Brett C. wrote:
> Is this a bug, or are the docs wrong?  I am hoping it is the former 
> since if it is the latter my thesis just got a big caveat pasted into it 
> about how 'eval' can cause problems and invalidate the type inferencing 
> in irreparable ways.

There is another improbable way to bind variables with eval, with list
comprehensions:

>>> eval("[x for x in [3]]")
[3]
>>> x
3

If the goal is not security but type inference, I guess both this and the
compile() trick should be considered as outside any reasonable spec.


A bientot,

Armin.




More information about the Python-Dev mailing list