classification
Title: unqualified exec in class body
Type: behavior Stage:
Components: Interpreter Core Versions: Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: jhylton Nosy List: amaury.forgeotdarc, fijal, jhylton, loewis, terry.reedy
Priority: normal Keywords: patch

Created on 2009-03-27 14:40 by fijal, last changed 2010-11-12 05:58 by terry.reedy. 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
2010-11-12 05:58:03terry.reedysetstatus: pending -> closed
2010-08-03 19:51:33terry.reedysetstatus: open -> pending
versions: - Python 2.6, Python 2.5, Python 2.4
nosy: + terry.reedy

messages: + msg112661
2009-04-01 13:51:26jhyltonsetmessages: + msg85009
2009-04-01 04:15:22loewissetstatus: closed -> open
nosy: + loewis
messages: + msg84976

2009-03-31 16:12:45jhyltonsetstatus: open -> closed
resolution: accepted -> rejected
messages: + msg84820
2009-03-30 18:14:10jhyltonsettype: behavior

resolution: accepted
assignee: jhylton
nosy: + jhylton
2009-03-27 14:54:58amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg84262
2009-03-27 14:40:56fijalcreate