Created
January 19, 2017 06:03
-
-
Save himanoa/6839502e86c5655c71f5c2ff7817bcf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from typing import * | |
from functools import wraps | |
def exception(f: Callable[[Any], Any]) -> Callable[[Any], Union[Exception, Any]]: | |
@wraps(f) | |
def wrapper(*args, **kwargs): | |
try: | |
return f(*args, **kwargs) | |
except Exception as e: | |
return e | |
return wrapper | |
@exception | |
def hoge(fuga: int) -> Union[Exception, int]: | |
if fuga == 3: | |
raise Exception("だめだよ") | |
return fuga | |
if __name__ == '__main__': | |
a = hoge(3) | |
a = a + 3 | |
# mypy fuck_try_catch.py | |
# testing.py:23: error: Unsupported operand types for + ("Union[Exception, Any]" and "int") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment