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.

classification
Title: Function variable wrongly reported unassigned
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: adrianmay, ezio.melotti
Priority: normal Keywords:

Created on 2010-01-21 07:32 by adrianmay, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bug.py adrianmay, 2010-01-21 07:32 Code to demo the bug
Messages (3)
msg98101 - (view) Author: Adrian May (adrianmay) Date: 2010-01-21 07:32
Hi folks,

The attached program says:

$ ./bug.py
a
None
b
Traceback (most recent call last):
  File "./bug.py", line 49, in <module>
    print number(s)
  File "./bug.py", line 34, in foo
    while eat != None:
UnboundLocalError: local variable 'eat' referenced before assignment

but I reckon it is assigned. (I haven't tried it on a newer python because the junk I want to use with python says it only works with 2.5.2.) 

Cheers, Adrian.
msg98102 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-01-21 07:48
This is not a bug, see http://docs.python.org/faq/programming.html#why-am-i-getting-an-unboundlocalerror-when-the-variable-has-a-value
msg98104 - (view) Author: Adrian May (adrianmay) Date: 2010-01-21 11:20
OK, Thanks. Sorry for the hassle.

Adrian.
History
Date User Action Args
2022-04-11 14:56:56adminsetgithub: 51995
2010-01-21 15:17:03r.david.murraysetpriority: normal
type: compile error -> behavior
2010-01-21 11:20:13adrianmaysettype: behavior -> compile error
messages: + msg98104
2010-01-21 07:48:00ezio.melottisetstatus: open -> closed

type: compile error -> behavior

nosy: + ezio.melotti
messages: + msg98102
resolution: not a bug
stage: resolved
2010-01-21 07:32:38adrianmaycreate