We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The two functions error_from_state_[ok|bad]() below are pretty much equivalent; one use an if statement, the other uses a conditional expression.
error_from_state_[ok|bad]()
Mypy reports an error only in the expression case. I would expect the result to be the same.
from typing import Type, Optional def class_for_state(state: bytes) -> Type[Exception]: return TypeError def error_from_state_ok(state: Optional[bytes]) -> Exception: if state is not None: cls = class_for_state(state) else: cls = ValueError return cls("message") def error_from_state_bad(state: Optional[bytes]) -> Exception: cls = class_for_state(state) if state is not None else ValueError return cls("message")
mypy --strict reports:
mypy --strict
$ mypy --strict mypyerr.py mypyerr.py:16: error: Returning Any from function declared to return "Exception"
Tested with Python 3.6 and mypy 0.770 and master.
The text was updated successfully, but these errors were encountered:
This is basically #4134.
Sorry, something went wrong.
No branches or pull requests
The two functions
error_from_state_[ok|bad]()
below are pretty much equivalent; one use an if statement, the other uses a conditional expression.Mypy reports an error only in the expression case. I would expect the result to be the same.
mypy --strict
reports:Tested with Python 3.6 and mypy 0.770 and master.
The text was updated successfully, but these errors were encountered: