Skip to content

False exception error in except clause with a ternary conditional operator #7356

Description

@serhiy-storchaka
import sys
try:
    f = open('.', 'rb')
except PermissionError if sys.platform == "win32" else ():
    pass

MyPy reports an error:

e.py:4: error: Exception type must be derived from BaseException

Actually except accepts either an exception type, or a tuple of exception types (including an empty tuple).

(PermissionError,) if sys.platform == "win32" else () also causes an error. But (PermissionError,) if sys.platform == "win32" else (IsADirectoryError,) is accepted by MyPy.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions