classification
Title: invalid exception handling in Lib/ctypes/macholib/dyld.py
Type: behavior Stage: resolved
Components: ctypes, Library (Lib) Versions: Python 3.7, Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, belopolsky, berker.peksag, inada.naoki, madison.may, meador.inge, python-dev, ronaldoussoren, scoder
Priority: normal Keywords: patch

Created on 2013-08-31 10:56 by scoder, last changed 2017-03-31 16:36 by dstufft. This issue is now closed.

Files
File name Uploaded Description Edit
issue18893.diff madison.may, 2013-09-02 21:01 2 to 3 migration for framework_find error handling review
Pull Requests
URL Status Linked Edit
PR 552 closed dstufft, 2017-03-31 16:36
Messages (7)
msg196629 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2013-08-31 10:56
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:
        Python
        Python.framework
        Python.framework/Versions/Current
    """
    try:
        return dyld_find(fn, executable_path=executable_path, env=env)
    except ValueError as e:
        pass
    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]))
    try:
        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.
msg196630 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2013-08-31 11:21
changing title as it doesn't really look like a typo, more a "converto"
msg196772 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-09-02 06:05
Your analysis looks correct to me, that is "raise e" is supposed to raise the exception caught by the first try block.
msg196807 - (view) Author: Madison May (madison.may) * Date: 2013-09-02 21:01
Seems like a simple fix -- patch attached.
msg277324 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2016-09-24 17:41
lgtm
msg277455 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-26 20:06
New changeset e9f34d382eda by Berker Peksag in branch '3.5':
Issue #18893: Fix invalid exception handling in Lib/ctypes/macholib/dyld.py
https://hg.python.org/cpython/rev/e9f34d382eda

New changeset 708337cd8e6a by Berker Peksag in branch '3.6':
Issue #18893: Merge from 3.5
https://hg.python.org/cpython/rev/708337cd8e6a

New changeset b9d9c49d5b50 by Berker Peksag in branch 'default':
Issue #18893: Merge from 3.6
https://hg.python.org/cpython/rev/b9d9c49d5b50
msg277456 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-09-26 20:06
Thanks!
History
Date User Action Args
2017-03-31 16:36:34dstufftsetpull_requests: + pull_request1073
2016-09-26 20:06:40berker.peksagsetstatus: open -> closed

versions: + Python 3.7
nosy: + berker.peksag

messages: + msg277456
resolution: fixed
stage: resolved
2016-09-26 20:06:16python-devsetnosy: + python-dev
messages: + msg277455
2016-09-24 17:41:59inada.naokisetversions: + Python 2.7, Python 3.5, Python 3.6, - Python 3.2, Python 3.3, Python 3.4
2016-09-24 17:41:35inada.naokisetnosy: + inada.naoki
messages: + msg277324
2013-09-02 21:01:44madison.maysetfiles: + issue18893.diff

nosy: + madison.may
messages: + msg196807

keywords: + patch
2013-09-02 06:05:04ronaldoussorensetmessages: + msg196772
2013-09-01 07:28:06ned.deilysetnosy: + ronaldoussoren
2013-08-31 11:21:00scodersetmessages: + msg196630
title: typo in Lib/ctypes/macholib/dyld.py -> invalid exception handling in Lib/ctypes/macholib/dyld.py
2013-08-31 11:04:22pitrousetnosy: + amaury.forgeotdarc, belopolsky, meador.inge
2013-08-31 10:56:26scodercreate