Closed
Description
I faced with a strange mypy error, with such a code below:
def foo() -> None:
message = 'test'
raise Exception(message) if message else Exception # -> mypy error
def bar() -> None:
raise Exception # ok
def baz() -> None:
message = 'test'
raise Exception(message) # ok
def qux() -> None:
message = 'test'
raise Exception if not message else Exception(message) # -> mypy error
if __name__ == '__main__':
foo()
It seems legal code, but mypy produces two error messages there.
$ mypy test.py
test.py:3: error: Exception must be derived from BaseException
test.py:17: error: Exception must be derived from BaseException
Actually, this error seems to happen not only with Exception
but with any other built-in exceptions.
The version of mypy is 0.600, and that of Python is 3.6.3.
Thanks in advance.