PyCQA / flake8-bugbear

A plugin for Flake8 finding likely bugs and design problems in your program. Contains warnings that don't belong in pyflakes and pycodestyle.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Warn on `except A | B:`, which is a runtime error

Zac-HD opened this issue · comments

t = ZeroDivisionError | ValueError           # Python 3.10 syntax for types.UnionType
assert isinstance(ZeroDivisionError(), t)    # isinstance and issubclass work

try: 
    1/0
except ZeroDivisionError | ValueError as e:  # but this fails!
    print(e)
Traceback (most recent call last):
  File "demo.py", line 5, in <module>
    1/0
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "demo.py", line 6, in <module>
    except ZeroDivisionError | ValueError as e: 
TypeError: catching classes that do not inherit from BaseException is not allowed

I think we should have a lint warning for this, since I've seen it bite in the wild and it will remain an error going forward.

I think I already made this happen: test.py:3:1: B030 Except handlers should only be names of exception classes.

🤦‍♂️ just needed to update to the latest version, yep. Cheers Jelle!