New submission from Pierre-Antoine BRAMERET:
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 "", line 1, in
File "", 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 "", line 1, in
File "", 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.
--
messages: 228757
nosy: Miaou
priority: normal
severity: normal
status: open
title: super() and del in the same method leads to UnboundLocalError
versions: Python 2.7, Python 3.2, Python 3.4
___
Python tracker
<http://bugs.python.org/issue22574>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com