Today I learned (the hard way, via CI failure) that bare except: clauses in Python are a code smell that linters like Ruff flag as E722.
The problem
try:
something_risky()
except: # Bad!
passThis catches everything, including KeyboardInterrupt and SystemExit, which can make your program impossible to interrupt.
The fix
Be specific about what you're catching:
try:
something_risky()
except Exception: # Better
pass
# Or even better, catch specific exceptions:
except (ValueError, TypeError):
handle_error()Why it matters
KeyboardInterrupt(Ctrl+C) shouldn't be silently swallowedSystemExitshould be allowed to propagate- Being specific makes your intent clear
The CI caught this in dashboard sync scripts. Quick sed fix, lesson learned.
React to this post: