Bugs item #861340, was opened at 2003-12-16 17:09 Message generated for change (Comment added) made by montanaro You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=861340&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Library Group: Python 2.3 >Status: Closed >Resolution: Out of Date Priority: 5 Submitted By: Jeremy Fincher (jemfinch) Assigned to: Skip Montanaro (montanaro) Summary: UnboundLocalError in cgitb.py Initial Comment: Here's the exception: Exception return cgitb.text((E, e, tb)).rstrip('\r\n') File "/usr/lib/python2.3/cgitb.py", line 197, in text vars = scanvars(reader, frame, locals) File "/usr/lib/python2.3/cgitb.py", line 76, in scanvars parent = value UnboundLocalError: local variable 'value' referenced before assignment And here's the code: if lasttoken == '.': if parent is not __UNDEF__: value = getattr(parent, token, __UNDEF__) vars.append((prefix + token, prefix, value)) else: where, value = lookup(token, frame, locals) vars.append((token, where, value)) elif token == '.': prefix += lasttoken + '.' parent = value If lasttoken is '.' and parent is __UNDEF__, value doesn't get set. I'd offer a patch, but I really have no idea what this code is doing and so don't know what to set value to. ---------------------------------------------------------------------- >Comment By: Skip Montanaro (montanaro) Date: 2005-05-19 22:26 Message: Logged In: YES user_id=44345 Looks like this was fixed at some point. The local variable value is clearly initialized in scanvars() at this point. ---------------------------------------------------------------------- Comment By: Neal Norwitz (nnorwitz) Date: 2003-12-18 17:32 Message: Logged In: YES user_id=33168 Jeremy, that's still not enough to reproduce the bug. What exception was thrown by the code below and from where? What were the values of bugs, searchstr, and keywords? What are the definitions for utils.pluralize() and utils.commaAndify()? ---------------------------------------------------------------------- Comment By: Jeremy Fincher (jemfinch) Date: 2003-12-18 17:02 Message: Logged In: YES user_id=99508 The code that caused the raised exception (which subsequently triggered the exception in cgitb) was this: outputstr = '%d %s match \'%s\' (%s):' % (len(bugs), \ utils.pluralize(len(bugs), 'bug'), searchstr, utils.commaAndify(keywords, And='AND')) That's actually from the diff where I changed it to be a bit more idiomatic :) It wasn't my code, I promise! ---------------------------------------------------------------------- Comment By: Jeremy Fincher (jemfinch) Date: 2003-12-18 16:56 Message: Logged In: YES user_id=99508 To be honest, it's just something I ran into in my own test suite when my exception-handling logging code caught an exception I didn't expect to get raised. Since I have no idea what the code in cgitb that's raising the exception is actually doing, I really don't know how to begin to try and narrow it down to a test case. ---------------------------------------------------------------------- Comment By: Skip Montanaro (montanaro) Date: 2003-12-18 11:31 Message: Logged In: YES user_id=44345 I pulled scanvars() and lookup() out into a separate file and instrumented things a little. From staring at the code I thought that perhaps it didn't handle the case where the line starts with a dot separating an object and its attribute. I can't provoke a failure in that situation though. See attached lookup.py. Jeremy, can you fiddle it to make it fail? ---------------------------------------------------------------------- Comment By: Skip Montanaro (montanaro) Date: 2003-12-18 10:13 Message: Logged In: YES user_id=44345 Sorry, I have no idea what it does either. I'll look into it a bit, but don't expect a miracle. :-( ---------------------------------------------------------------------- Comment By: Neal Norwitz (nnorwitz) Date: 2003-12-18 09:02 Message: Logged In: YES user_id=33168 Jeremy, can you attach a complete test case? Skip, I realize you didn't write the scanvars code (Ping did), but you did add text. So maybe you have an idea. >From a brief scan, it looks like if value is initialized to None, the code might work. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=861340&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com