PEP 760 – No More Bare Excepts

I know this is off-topic for this thread, but I raised this as an issue with the PEP 760 PR (the PEP itself hasn’t been published yet). I haven’t had time to look at the response from the PEP authors, but I would really like to preserve bare-except with an unconditional raise use case. If that can’t be done, I suggested an alias for BaseException called AnyException so at least the modified code would read better:

try:
    something()
except:
     transaction.abort()
     raise
else:
     transaction.commit()

would become

try:
    something()
except AnyException:
     transaction.abort()
     raise
else:
     transaction.commit()
6 Likes