[Python-Dev] PEP 3000 and exec (original) (raw)
Guido van Rossum guido at python.org
Tue Oct 11 00:05:56 CEST 2005
- Previous message: [Python-Dev] PEP 3000 and exec
- Next message: [Python-Dev] PEP 3000 and exec
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
My idea was to make the compiler smarter so that it would recognize exec() even if it was just a function.
Another idea might be to change the exec() spec so that you are required to pass in a namespace (and you can't use locals() either!). Then the whole point becomes moot.
On 10/10/05, skip at pobox.com <skip at pobox.com> wrote:
>> This might be minor-- but I didn't see anyone mentioning it so far. >> If
exec
functionality is to be provided, then I think it still >> should be a keyword for the parser to know; currently bytecode >> generation is affected ifexec
is present. Even if that changes >> for Python 3k (we don't know yet), the paragraph for exec should be >> annotated with a note about this issue.Brett> But the PEP says that 'exec' will become a function and thus no Brett> longer become a built-in, so changing the grammar is not needed. I don't think that was the OP's point though it might not have been terribly clear. Today, the presence of the exec statement in a function changes how non-local load instructions are generated. Consider f and g with their dis.dis output: >>> def f(a): ... exec "import %s" % a ... print q ... >>> def g(a): ... import(a) ... print q ... >>> dis.dis(f) 2 0 LOADCONST 1 ('import %s') 3 LOADFAST 0 (a) 6 BINARYMODULO 7 LOADCONST 0 (None) 10 DUPTOP 11 EXECSTMT 3 12 LOADNAME 1 (q) 15 PRINTITEM 16 PRINTNEWLINE 17 LOADCONST 0 (None) 20 RETURNVALUE >>> dis.dis(g) 2 0 LOADGLOBAL 0 (import) 3 LOADFAST 0 (a) 6 CALLFUNCTION 1 9 POPTOP 3 10 LOADGLOBAL 2 (q) 13 PRINTITEM 14 PRINTNEWLINE 15 LOADCONST 0 (None) 18 RETURNVALUE If the exec statement is replaced by a function, how will the bytecode generator know that q should be looked up using LOADNAME instead of LOADGLOBAL? Maybe it's a non-issue, but even if so, a note to that affect on the wiki page might be worthwhile. Skip
Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] PEP 3000 and exec
- Next message: [Python-Dev] PEP 3000 and exec
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]