Skip to content

ENH: Except BaseException in numpy.lookfor again #22345

@lagru

Description

@lagru

Proposed new feature or change:

I apologize if this is not the correct channel to inquire. However, over at scikit-image we've encountered a problem using numpy.lookfor on our own library, see scikit-image/scikit-image#6548.

The problem seems to be stemming from a narrower Exception handling introduced by #19393. In our test modules, which lookfor tries to import, we use pytest's importorskip which raises Skipped. Unfortunately Skippd does only inherit from BaseException and is therefore not handled gracefully by

except (Exception, SystemExit):

As I see no other cause in #19393 than fixing a LGTM alert as the reason for this change, I'd like to inquire if we can revert that change. That's likely an easier fix than what we can do on scikit-image's site. Looking at the exception hierarchy I'm curious if there is a reason why GeneratorExit and other classes only deriving from BaseException should not be caught while everything else is fine. I get KeyboardInterrupt, which enables the user to interrupt this function. But then again why is SystemExit caught? In any case the current behavior could be preserved with something like

    ...
except KeyBoardInterrupt:
    raise
except BaseException:
    continue

or some version thereof.

Whether this a bug on NumPy's side might depend on if the module parameter implies that other modules outside NumPy should be supported. Thanks in advance for the feedback.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions