This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Miaou
Recipients Miaou
Date 2014-10-07.09:48:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1412675295.92.0.427134120521.issue22574@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-10-07 09:48:16Miaousetrecipients: + Miaou
2014-10-07 09:48:15Miaousetmessageid: <1412675295.92.0.427134120521.issue22574@psf.upfronthosting.co.za>
2014-10-07 09:48:15Miaoulinkissue22574 messages
2014-10-07 09:48:15Miaoucreate