Skip to content

Fix bare except: use specific exception types#14000

Open
koteshyelamati wants to merge 2 commits into
explosion:masterfrom
koteshyelamati:master
Open

Fix bare except: use specific exception types#14000
koteshyelamati wants to merge 2 commits into
explosion:masterfrom
koteshyelamati:master

Conversation

@koteshyelamati

Copy link
Copy Markdown

Replace bare except: clauses with specific exception types:

  • spacy/ml/callbacks.py: except Exception: (guards inspect.signature() which can fail for Cython methods)
  • spacy/cli/_util.py: except Exception: (guards run_command("git --version"))

Bare except: catches BaseException including SystemExit and KeyboardInterrupt.

Handle exceptions specifically when setting function signature.
Catch specific exceptions when running git command.

@rkfshakti rkfshakti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean fix. Replacing bare except: with except Exception: is the right approach — it prevents catching SystemExit/KeyboardInterrupt while still catching the expected runtime errors from inspect.signature() and run_command.

Both call sites are appropriate: inspect.signature() can raise ValueError for builtins, and run_command could raise various OSError/subprocess exceptions. Using except Exception is the minimal safe widening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants