[Python-Dev] variable name resolution in exec is incorrect
Colin H
hawkett at gmail.com
Thu May 27 16:14:44 CEST 2010
Just to put a couple of alternatives on the table that don't break
existing code - not necessarily promoting them, or suggesting they
would be easy to do -
1. modify exec() to take an optional third argument - 'scope_type' -
if it is not supplied (but locals is), then it runs as class namespace
- i.e. identical to existing behaviour. If it is supplied then it will
run as whichever is specified, with function namespace being an
option. The API already operates along these lines, with the second
argument being optional and implying module namespace if it is not
present.
2. a new API exec2() which uses function namespace, and deprecating
the old exec() - assuming there is agreement that function namespace
makes more sense than the class namespace, because there are real use
cases, and developers would generally expect this behaviour when
approaching the API for the first time.
More information about the Python-Dev
mailing list