Issue 5578: unqualified exec in class body (original) (raw)

Created on 2009-03-27 14:40 by fijal, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
out.diff fijal,2009-03-27 14:40 review
Messages (6)
msg84259 - (view) Author: Maciek Fijalkowski (fijal) Date: 2009-03-27 14:40
A patch and a test. The problem is a bit broader - what about import * etc? Patch fixes that, but without a test.
msg84262 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-03-27 14:54
Why should this code fail? I cannot see the problem you try to solve.
msg84820 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2009-03-31 16:12
exec is allowed in a class statement
msg84976 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-04-01 04:15
Reopening. The following piece of code changed it behavior between 2.5 and 2.6: def f(): a = 2 class C: exec 'a = 42' abc = a return C print f().abc In 2.6, this returns 2, because static analysis determines that the read of 'a' comes from f's closure, yet the exec gets a new set of locals for the body of C where it stores into. This is highly counter-intuitive. For functions, the issue is resolved by banning exec; the same should (now) happen for classes.
msg85009 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2009-04-01 13:51
Why did it change from 2.5 to 2.6? I'm not sure that the change makes any sense. (Dreading the answer that I changed it...)
msg112661 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-08-03 19:51
Is there any currently relevant discrepancy between doc and behavior claimed in this issue. As far as I can see, the 2.7 docs for exec and def make no mention of exec being prohibited in def, let alone class statements. Ditto for exec() in 3.x. Anything earlier is out-of-date.
History
Date User Action Args
2022-04-11 14:56:47 admin set github: 49828
2010-11-12 05:58:03 terry.reedy set status: pending -> closed
2010-08-03 19:51:33 terry.reedy set status: open -> pendingversions: - Python 2.6, Python 2.5, Python 2.4nosy: + terry.reedymessages: +
2009-04-01 13:51:26 jhylton set messages: +
2009-04-01 04:15:22 loewis set status: closed -> opennosy: + loewismessages: +
2009-03-31 16:12:45 jhylton set status: open -> closedresolution: accepted -> rejectedmessages: +
2009-03-30 18:14:10 jhylton set type: behaviorresolution: acceptedassignee: jhyltonnosy: + jhylton
2009-03-27 14:54:58 amaury.forgeotdarc set nosy: + amaury.forgeotdarcmessages: +
2009-03-27 14:40:56 fijal create