-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[1.20 regression] no longer accepts the empty tuple for except ...: #21152
Description
Bug Report
mypy 1.20 no longer considers the empty tuple as a valid argument to except ...: unless it is explicitly annotated to be a (potentially empty) tuple of exception types. May be related to #17762 since the PR seems to be the last one that touched the exception-type-tuple handling for try-except block.
(Same context as #21149: the repo, the failed pipeline, and the caveat about mypy-version behaviors not lining up between mypy Playground and PyPI releases.)
To Reproduce
(Gist: https://gist.github.com/mypy-play/d0bd152e2e868b693ca73079096d13c6)
def this_no_longer_works() -> None:
try:
pass
except ():
assert False, 'This should be unreachable'
def but_this_still_does() -> None:
accepted_errors: tuple[type[Exception], ...] = ()
try:
pass
except accepted_errors:
pass(The real repo code of course doesn't just do a redundant try: ... except: ..., but uses it for e.g. optional post-mortem debugging.)
Expected Behavior
Type-check passes as with before
Actual Behavior
main.py:4: error: Exception type must be derived from BaseException (or be a tuple of exception classes) [misc]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: master (on Playground)
- Mypy command-line flags: nil
- Mypy configuration options from
mypy.ini(and other config files): nil - Python version used: 3.14