[New-bugs-announce] [issue18893] typo in Lib/ctypes/macholib/dyld.py

Stefan Behnel report at bugs.python.org
Sat Aug 31 12:56:26 CEST 2013

New submission from Stefan Behnel:

The exception handling clauses in framework_find() are weird.

def framework_find(fn, executable_path=None, env=None):
    Find a framework using dyld semantics in a very loose manner.

    Will take input such as:
        return dyld_find(fn, executable_path=executable_path, env=env)
    except ValueError as e:
    fmwk_index = fn.rfind('.framework')
    if fmwk_index == -1:
        fmwk_index = len(fn)
        fn += '.framework'
    fn = os.path.join(fn, os.path.basename(fn[:fmwk_index]))
        return dyld_find(fn, executable_path=executable_path, env=env)
    except ValueError:
        raise e

My guess is that this is left-over code from Py2.x. Since it doesn't make sense to catch an exception in the second clause just to re-raise it, I think the intention was really to re-raise the original exception caught in the first clause, which no longer works that way in Py3.

The fix would then be to assign the exception to a new variable in the first except clause and re-raise that in the second.

I found this problem because Cython rejected the module with a compile error about "e" being undefined in the last line.

components: Library (Lib), ctypes
messages: 196629
nosy: scoder
priority: normal
severity: normal
status: open
title: typo in Lib/ctypes/macholib/dyld.py
type: behavior
versions: Python 3.2, Python 3.3, Python 3.4

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list