|
10 | 10 | reveal_type(test) # N: Revealed type is "def () -> returns.result.Result[builtins.int, builtins.Exception]"
|
11 | 11 |
|
12 | 12 |
|
| 13 | +- case: safe_decorator_passing_exceptions_no_params |
| 14 | + disable_cache: false |
| 15 | + main: | |
| 16 | + from returns.result import safe |
| 17 | +
|
| 18 | + @safe((ValueError,)) |
| 19 | + def test() -> int: |
| 20 | + return 1 |
| 21 | +
|
| 22 | + reveal_type(test) # N: Revealed type is "def () -> returns.result.Result[builtins.int, builtins.Exception]" |
| 23 | +
|
| 24 | + @safe(exceptions=(ValueError,)) |
| 25 | + def test2() -> int: |
| 26 | + return 1 |
| 27 | +
|
| 28 | + reveal_type(test2) # N: Revealed type is "def () -> returns.result.Result[builtins.int, builtins.Exception]" |
| 29 | +
|
| 30 | +
|
13 | 31 | - case: safe_composition_no_params
|
14 | 32 | disable_cache: false
|
15 | 33 | main: |
|
|
21 | 39 | reveal_type(safe(test)) # N: Revealed type is "def () -> returns.result.Result[builtins.int, builtins.Exception]"
|
22 | 40 |
|
23 | 41 |
|
| 42 | +- case: safe_composition_passing_exceptions_no_params |
| 43 | + disable_cache: false |
| 44 | + main: | |
| 45 | + from returns.result import safe |
| 46 | +
|
| 47 | + def test() -> int: |
| 48 | + return 1 |
| 49 | +
|
| 50 | + reveal_type(safe((EOFError,))(test)) # N: Revealed type is "def () -> returns.result.Result[builtins.int, builtins.Exception]" |
| 51 | +
|
| 52 | +
|
24 | 53 | - case: safe_decorator_with_args
|
25 | 54 | disable_cache: false
|
26 | 55 | main: |
|
|
34 | 63 | reveal_type(test) # N: Revealed type is "def (first: builtins.int, second: Union[builtins.str, None] =, *, kw: builtins.bool =) -> returns.result.Result[builtins.int, builtins.Exception]"
|
35 | 64 |
|
36 | 65 |
|
| 66 | +- case: safe_decorator_passing_exceptions_with_args |
| 67 | + disable_cache: false |
| 68 | + main: | |
| 69 | + from typing import Optional |
| 70 | + from returns.result import safe |
| 71 | +
|
| 72 | + @safe((ValueError, EOFError)) |
| 73 | + def test(first: int, second: Optional[str] = None, *, kw: bool = True) -> int: |
| 74 | + return 1 |
| 75 | +
|
| 76 | + reveal_type(test) # N: Revealed type is "def (first: builtins.int, second: Union[builtins.str, None] =, *, kw: builtins.bool =) -> returns.result.Result[builtins.int, builtins.Exception]" |
| 77 | +
|
| 78 | +
|
37 | 79 | - case: safe_composition_with_args
|
38 | 80 | disable_cache: false
|
39 | 81 | main: |
|
|
46 | 88 | reveal_type(safe(test)) # N: Revealed type is "def (first: builtins.int, second: Union[builtins.str, None] =, *, kw: builtins.bool =) -> returns.result.Result[builtins.int, builtins.Exception]"
|
47 | 89 |
|
48 | 90 |
|
| 91 | +- case: safe_composition_passing_exceptions_with_args |
| 92 | + disable_cache: false |
| 93 | + main: | |
| 94 | + from typing import Optional |
| 95 | + from returns.result import safe |
| 96 | +
|
| 97 | + def test(first: int, second: Optional[str] = None, *, kw: bool = True) -> int: |
| 98 | + return 1 |
| 99 | +
|
| 100 | + reveal_type(safe((ValueError,))(test)) # N: Revealed type is "def (first: builtins.int, second: Union[builtins.str, None] =, *, kw: builtins.bool =) -> returns.result.Result[builtins.int, builtins.Exception]" |
| 101 | +
|
| 102 | +
|
49 | 103 | - case: safe_regression333
|
50 | 104 | disable_cache: false
|
51 | 105 | main: |
|
|
59 | 113 | reveal_type(send) # N: Revealed type is "def (text: builtins.str) -> returns.result.Result[Any, builtins.Exception]"
|
60 | 114 |
|
61 | 115 |
|
| 116 | +- case: safe_passing_exceptions_regression333 |
| 117 | + disable_cache: false |
| 118 | + main: | |
| 119 | + from returns.result import safe |
| 120 | + from typing import Any |
| 121 | +
|
| 122 | + @safe((Exception,)) |
| 123 | + def send(text: str) -> Any: |
| 124 | + return "test" |
| 125 | +
|
| 126 | + reveal_type(send) # N: Revealed type is "def (text: builtins.str) -> returns.result.Result[Any, builtins.Exception]" |
| 127 | +
|
| 128 | +
|
62 | 129 | - case: safe_regression641
|
63 | 130 | disable_cache: false
|
64 | 131 | main: |
|
|
72 | 139 | reveal_type(safe(tap(Response.raise_for_status))) # N: Revealed type is "def (main.Response*) -> returns.result.Result[main.Response, builtins.Exception]"
|
73 | 140 |
|
74 | 141 |
|
| 142 | +- case: safe_passing_exceptions_regression641 |
| 143 | + disable_cache: false |
| 144 | + main: | |
| 145 | + from returns.result import safe |
| 146 | + from returns.functions import tap |
| 147 | +
|
| 148 | + class Response(object): |
| 149 | + def raise_for_status(self) -> None: |
| 150 | + ... |
| 151 | +
|
| 152 | + reveal_type(safe((EOFError,))(tap(Response.raise_for_status))) # N: Revealed type is "def (main.Response*) -> returns.result.Result[main.Response, builtins.Exception]" |
| 153 | +
|
| 154 | +
|
75 | 155 | - case: safe_decorator_with_args_kwargs
|
76 | 156 | disable_cache: false
|
77 | 157 | main: |
|
|
84 | 164 | reveal_type(test) # N: Revealed type is "def (*args: Any, **kwargs: Any) -> returns.result.Result[builtins.int, builtins.Exception]"
|
85 | 165 |
|
86 | 166 |
|
| 167 | +- case: safe_decorator_passing_exceptions_with_args_kwargs |
| 168 | + disable_cache: false |
| 169 | + main: | |
| 170 | + from returns.result import safe |
| 171 | +
|
| 172 | + @safe((EOFError,)) |
| 173 | + def test(*args, **kwargs) -> int: |
| 174 | + return 1 |
| 175 | +
|
| 176 | + reveal_type(test) # N: Revealed type is "def (*args: Any, **kwargs: Any) -> returns.result.Result[builtins.int, builtins.Exception]" |
| 177 | +
|
| 178 | +
|
87 | 179 | - case: safe_decorator_with_args_kwargs
|
88 | 180 | disable_cache: false
|
89 | 181 | main: |
|
|
96 | 188 | reveal_type(test) # N: Revealed type is "def (*args: builtins.int, **kwargs: builtins.str) -> returns.result.Result[builtins.int, builtins.Exception]"
|
97 | 189 |
|
98 | 190 |
|
| 191 | +- case: safe_decorator_passing_exceptions_with_args_kwargs |
| 192 | + disable_cache: false |
| 193 | + main: | |
| 194 | + from returns.result import safe |
| 195 | +
|
| 196 | + @safe((Exception,)) |
| 197 | + def test(*args: int, **kwargs: str) -> int: |
| 198 | + return 1 |
| 199 | +
|
| 200 | + reveal_type(test) # N: Revealed type is "def (*args: builtins.int, **kwargs: builtins.str) -> returns.result.Result[builtins.int, builtins.Exception]" |
| 201 | +
|
| 202 | +
|
99 | 203 | - case: safe_decorator_composition
|
100 | 204 | disable_cache: false
|
101 | 205 | main: |
|
|
108 | 212 | return 1
|
109 | 213 |
|
110 | 214 | reveal_type(test) # N: Revealed type is "def (*args: builtins.int, **kwargs: builtins.str) -> returns.io.IO[returns.result.Result*[builtins.int*, builtins.Exception]]"
|
| 215 | +
|
| 216 | +
|
| 217 | +- case: safe_decorator_passing_exceptions_composition |
| 218 | + disable_cache: false |
| 219 | + main: | |
| 220 | + from returns.io import impure |
| 221 | + from returns.result import safe |
| 222 | +
|
| 223 | + @impure |
| 224 | + @safe((ValueError,)) |
| 225 | + def test(*args: int, **kwargs: str) -> int: |
| 226 | + return 1 |
| 227 | +
|
| 228 | + reveal_type(test) # N: Revealed type is "def (*args: builtins.int, **kwargs: builtins.str) -> returns.io.IO[returns.result.Result*[builtins.int*, builtins.Exception]]" |
0 commit comments