Skip to content

Commit 221cac4

Browse files
committed
Include example and docs for Maybe
1 parent b129c19 commit 221cac4

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

docs/source/api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ API Reference
1616

1717
.. py:data:: Maybe
1818
:value: Value[T] | Error
19+
A convenience alias to a union of both results. This allows type checkers to perform
20+
exhaustiveness checking when ``isinstance()`` is used with either class::
21+
22+
outcome: Maybe[int] = capture(some_function, 1, 2, 3)
23+
if isinstance(outcome, Value):
24+
# Type checkers know it's a Value[int] here.
25+
else:
26+
# It must be an Error.
1927

2028
.. autoclass:: Value
2129
:members:

src/outcome/_impl.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,5 @@ async def asend(self, agen: AsyncGenerator[ResultT, NoReturn]) -> ResultT:
235235
return await agen.athrow(self.error)
236236

237237

238+
# A convenience alias to a union of both results, allowing exhaustiveness checking.
238239
Maybe = Union[Value[ValueT], Error]
239-
"""
240-
A convenience alias to a union of both results. This allows type checkers to perform
241-
exhaustiveness checking when ``isinstance()`` is used with either class.
242-
"""

0 commit comments

Comments
 (0)