Skip to content

fix: replace bare except with except BaseException in decorator - #1160

Open
harshadkhetpal wants to merge 1 commit into
prometheus:masterfrom
harshadkhetpal:fix/bare-except-decorator
Open

fix: replace bare except with except BaseException in decorator#1160
harshadkhetpal wants to merge 1 commit into
prometheus:masterfrom
harshadkhetpal:fix/bare-except-decorator

Conversation

@harshadkhetpal

Copy link
Copy Markdown

Summary

Replace bare except: with except BaseException: in prometheus_client/decorator.py (PEP 8 E722).

The bare except clause catches everything including SystemExit and KeyboardInterrupt. Since this block re-raises the exception, using except BaseException: preserves the exact same behavior while being explicit about the intent.

Change:

# Before
except:
    print('Error in generated code:', file=sys.stderr)
    print(src, file=sys.stderr)
    raise

# After
except BaseException:
    print('Error in generated code:', file=sys.stderr)
    print(src, file=sys.stderr)
    raise

Testing

No behavior change — the raise re-raises the caught exception regardless. BaseException catches everything just like bare except, but satisfies PEP 8 E722.

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

Labels

None yet

1 participant