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 Rodrigo.Ventura
Recipients Rodrigo.Ventura
Date 2011-05-06.22:53:04
SpamBayes Score 1.888261e-07
Marked as misclassified No
Message-id <1304722385.56.0.574647531565.issue12023@psf.upfronthosting.co.za>
In-reply-to
Content
Consider these two functions:
---
def nok():
    a = None
    def f():
        if a:
            a = 1
    f()

def ok():
    a = None
    def f():
        if a:
            b = 1
    f()
---

Function ok() executes fine, but function nok() trigger an exception:

Traceback (most recent call last):
  File "pb.py", line 20, in <module>
    nok()
  File "pb.py", line 7, in nok
    f()
  File "pb.py", line 5, in f
    if a:
UnboundLocalError: local variable 'a' referenced before assignment

There is no reason for this to happen

Regards,
Rodrigo Ventura
History
Date User Action Args
2011-05-06 22:53:05Rodrigo.Venturasetrecipients: + Rodrigo.Ventura
2011-05-06 22:53:05Rodrigo.Venturasetmessageid: <1304722385.56.0.574647531565.issue12023@psf.upfronthosting.co.za>
2011-05-06 22:53:04Rodrigo.Venturalinkissue12023 messages
2011-05-06 22:53:04Rodrigo.Venturacreate