Skip to content

Commit babfcdd

Browse files
committed
Delete whilespaces, generate new docs
1 parent 0333726 commit babfcdd

File tree

2 files changed

+68
-38
lines changed

2 files changed

+68
-38
lines changed

docs/result.md

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,22 @@ is_ok(result: 'Result[T, E]') → TypeGuard[Ok[T]]
5555

5656
A typeguard to check if a result is an Ok
5757

58-
Usage: ``` r: Result[int, str] = get_a_result()```
59-
``` if is_ok(r):``` ``` r # r is of type Ok[int]```
60-
``` elif is_err(r):``` ``` r # r is of type Err[str]```
58+
Usage:
6159

60+
```python
61+
62+
r: Result[int, str] = get_a_result()
63+
if is_ok(r):
64+
r # r is of type Ok[int]
65+
elif is_err(r):
66+
r # r is of type Err[str]
67+
68+
```
6269

6370

6471
---
6572

66-
<a href="https://github.com/rustedpy/result/blob/master/src/result/result.py#L517"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
73+
<a href="https://github.com/rustedpy/result/blob/master/src/result/result.py#L523"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
6774

6875
## <kbd>function</kbd> `is_err`
6976

@@ -73,15 +80,22 @@ is_err(result: 'Result[T, E]') → TypeGuard[Err[E]]
7380

7481
A typeguard to check if a result is an Err
7582

76-
Usage: ``` r: Result[int, str] = get_a_result()```
77-
``` if is_ok(r):``` ``` r # r is of type Ok[int]```
78-
``` elif is_err(r):``` ``` r # r is of type Err[str]```
83+
Usage:
7984

85+
```python
86+
87+
r: Result[int, str] = get_a_result()
88+
if is_ok(r):
89+
r # r is of type Ok[int]
90+
elif is_err(r):
91+
r # r is of type Err[str]
92+
93+
```
8094

8195

8296
---
8397

84-
<a href="https://github.com/rustedpy/result/blob/master/src/result/result.py#L530"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
98+
<a href="https://github.com/rustedpy/result/blob/master/src/result/result.py#L542"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
8599

86100
## <kbd>function</kbd> `do`
87101

@@ -93,22 +107,36 @@ Do notation for Result (syntactic sugar for sequence of `and_then()` calls).
93107

94108

95109

96-
Usage: ``` # This is similar to```
110+
Usage:
111+
112+
``` rust
113+
114+
// This is similar to
97115
use do_notation::m;
98116
let final_result = m! {
99117
x <- Ok("hello");
100118
y <- Ok(True);
101119
Ok(len(x) + int(y) + 0.5)
102120
};
103121

104-
``` final_result: Result[float, int] = do(``` Ok(len(x) + int(y) + 0.5) for x in Ok("hello") for y in Ok(True) )
122+
```
123+
124+
``` rust
125+
126+
final_result: Result[float, int] = do(
127+
Ok(len(x) + int(y) + 0.5)
128+
for x in Ok("hello")
129+
for y in Ok(True)
130+
)
131+
132+
```
105133

106134
NOTE: If you exclude the type annotation e.g. `Result[float, int]` your type checker might be unable to infer the return type. To avoid an error, you might need to help it with the type hint.
107135

108136

109137
---
110138

111-
<a href="https://github.com/rustedpy/result/blob/master/src/result/result.py#L570"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
139+
<a href="https://github.com/rustedpy/result/blob/master/src/result/result.py#L591"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
112140

113141
## <kbd>function</kbd> `do_async`
114142

@@ -118,28 +146,26 @@ do_async(
118146
) → Result[T, E]
119147
```
120148

121-
Async version of do. Example:
149+
Async version of do. Example: ```
150+
``` python
122151

123-
``` final_result: Result[float, int] = await do_async(```
124-
Ok(len(x) + int(y) + z)
125-
for x in await get_async_result_1()
126-
for y in await get_async_result_2()
127-
for z in get_sync_result_3()
128-
)
152+
final_result: Result[float, int] = await do_async( Ok(len(x) + int(y) + z) for x in await get_async_result_1() for y in await get_async_result_2() for z in get_sync_result_3() )
153+
154+
```
129155

130156
NOTE: Python makes generators async in a counter-intuitive way.
131-
This is a regular generator:
132-
async def foo(): ...
133-
do(Ok(1) for x in await foo())
134-
135-
But this is an async generator:
136-
async def foo(): ...
137-
async def bar(): ...
138-
do(
139-
Ok(1)
140-
for x in await foo()
141-
for y in await bar()
142-
)
157+
158+
``` python
159+
160+
# This is a regular generator: async def foo(): ... do(Ok(1) for x in await foo())
161+
162+
```
163+
164+
``` python
165+
166+
# But this is an async generator: async def foo(): ... async def bar(): ... do( Ok(1) for x in await foo() for y in await bar() )
167+
168+
```
143169

144170
We let users try to use regular `do()`, which works in some cases
145171
of awaiting async values. If we hit a case like above, we raise
@@ -149,14 +175,18 @@ See `do()`.
149175
However, for better usability, it's better for `do_async()` to also accept
150176
regular generators, as you get in the first case:
151177

152-
async def foo(): ...
153-
do(Ok(1) for x in await foo())
178+
``` python
179+
180+
async def foo(): ... do(Ok(1) for x in await foo())
181+
182+
```
154183

155184
Furthermore, neither mypy nor pyright can infer that the second case is
156185
actually an async generator, so we cannot annotate `do_async()`
157186
as accepting only an async generator. This is additional motivation
158187
to accept either.
159188

189+
```
160190
161191
162192
---

src/result/result.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Result[R, TBE]:
503503

504504
def is_ok(result: Result[T, E]) -> TypeGuard[Ok[T]]:
505505
"""A typeguard to check if a result is an Ok
506-
506+
507507
Usage:
508508
509509
```python
@@ -513,9 +513,9 @@ def is_ok(result: Result[T, E]) -> TypeGuard[Ok[T]]:
513513
r # r is of type Ok[int]
514514
elif is_err(r):
515515
r # r is of type Err[str]
516-
516+
517517
```
518-
518+
519519
"""
520520
return result.is_ok()
521521

@@ -525,14 +525,14 @@ def is_err(result: Result[T, E]) -> TypeGuard[Err[E]]:
525525
526526
Usage:
527527
528-
```python
528+
```python
529529
530530
r: Result[int, str] = get_a_result()
531531
if is_ok(r):
532532
r # r is of type Ok[int]
533533
elif is_err(r):
534534
r # r is of type Err[str]
535-
535+
536536
```
537537
538538
"""
@@ -544,7 +544,7 @@ def do(gen: Generator[Result[T, E], None, None]) -> Result[T, E]:
544544
545545
546546
Usage:
547-
547+
548548
``` rust
549549
550550
// This is similar to

0 commit comments

Comments
 (0)