[Python-Dev] issue5578 - explanation (original) (raw)
Jeremy Hylton jeremy at alum.mit.edu
Wed Apr 1 18:21:03 CEST 2009
- Previous message: [Python-Dev] issue5578 - explanation
- Next message: [Python-Dev] issue5578 - explanation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Eeek, I think it was me. Part of the AST changes involved raising a SyntaxError when exec was used in a scope that had a free variable, since the behavior is pretty much undefined. If the compiler decides a variable is free, then it can't be assigned to in the function body. The compiled exec code can't know whether the variable is local or free in the exec context, only that it should generate a STORE_NAME opcode. The STORE_NAME can't possibly work.
It looks like I did a bad job of documenting the change, though. I had forgotton about it ,because it was three or four years ago.
It looks like the same exception should be raised for the class statement.
Jeremy
On Wed, Apr 1, 2009 at 11:00 AM, R. David Murray <rdmurray at bitdance.com> wrote:
On Wed, 1 Apr 2009 at 13:12, Chris Withers wrote:
Guido van Rossum wrote:
Well hold on for a minute, I remember we used to have an exec statement in a class body in the standard library, to define some file methods in socket.py IIRC. But why an exec?! Surely there must be some other way to do this than an exec? Maybe, but this sure is gnarly code: s = ("def %s(self, *args): return self.sock.%s(*args)\n\n" _"%s.doc = realsocket.%s.doc_\n") for m in socketmethods: exec s % (m, m, m, m) del m, s Guido's memory is good, that's from the socketobject class in socket.py. --David
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/jeremy%40alum.mit.edu
- Previous message: [Python-Dev] issue5578 - explanation
- Next message: [Python-Dev] issue5578 - explanation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]