Message228757
Hi,
With the following code:
class Base(object): pass
class Foo(Base):
def __init__(self):
super(Foo,self).__init__()
if False:
del Foo
I expect that Foo() would give me a Foo instance. Instead, it raises the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in __init__
super(Foo,self).__init__()
UnboundLocalError: local variable 'Foo' referenced before assignment
I first suspected the "del Foo" statement is executed before the function is executed (while parsing or something), because the error tells Foo does not exists.
Howver, the problem is deeper than that: with the following modified code:
class Foo(Base):
def __init__(self):
assert 'Foo' in globals()
assert Foo
super(Foo,self).__init__()
if False:
del Foo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in __init__
super(Foo,self).__init__()
UnboundLocalError: local variable 'Foo' referenced before assignment
So: Foo IS in globals(), but cannot be accessed through Foo in the class because of the presence of 'del Foo' in the never reached part of the method. |
|
Date |
User |
Action |
Args |
2014-10-07 09:48:16 | Miaou | set | recipients:
+ Miaou |
2014-10-07 09:48:15 | Miaou | set | messageid: <1412675295.92.0.427134120521.issue22574@psf.upfronthosting.co.za> |
2014-10-07 09:48:15 | Miaou | link | issue22574 messages |
2014-10-07 09:48:15 | Miaou | create | |
|