Message 63856 - Python tracker (original) (raw)

Found a bug when trying to integrate figleaf coverage into trunk. I have ripped the code down to the smallest subset that still causes the behaviour. The code works on the latest release of Python 2.5 but is broken on trunk. It comes in two files. The first is the caller (figleaf):

import os import sys

def foo(f, e, o): pass

sys.settrace(foo)

import main execfile('test_broken.py', main.dict)

The second file is the test (test_broken.py):

This code breaks on trunk

def test_foo(): class CustomException(Exception): pass

class SomeClass:
    def foo(self):
        raise CustomException

# The error only appears with enough nested blocks.
if (True == True):
    try:
        raise IOError
    except CustomException:
        pass

It should raise IOError. When run, it gives the following output:

jerry-seutters-computer:~/code/python/core_wierd_bug_minimal jseutter$ ../core/python.exe figleaf
Traceback (most recent call last): File "figleaf", line 10, in execfile('test_broken.py', main.dict) File "test_broken.py", line 18, in test_foo() File "test_broken.py", line 15, in test_foo except CustomException: UnboundLocalError: local variable 'CustomException' referenced before assignment [10019 refs]