I walked over to Jack's office to explain why this wasn't a good idea,
and in the ensueing discussion we suddenly came up with the following
solution: make exec a statement instead of a function. The syntax
would be
exec <expression> [in <expression> [, <expression>]]
and the compiler can switch off any optimizations for functions
containing exec statements. There is a precedent for this: the same
happens when the compiler sees "from <module> import *", because it
can't tell what local variables the star will introduce.
The change will break some existing Python code: statements calling
exec() with an explicit global and/or local dictionary. The majority
of exec() function calls will still work since the extra parentheses
are harmless.
How about it?
--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>