Skip to content

Commit

Permalink
Version 0.6.0: Staving Stack Traces
Browse files Browse the repository at this point in the history
  • Loading branch information
chrilves committed Apr 9, 2021
1 parent 8c687e4 commit 1462ab8
Show file tree
Hide file tree
Showing 34 changed files with 2,309 additions and 675 deletions.
2 changes: 1 addition & 1 deletion conda/raffiot/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set name = "raffiot" %}
{% set version = "0.5.2" %}
{% set version = "0.6.0" %}

package:
name: "{{ name|lower }}"
Expand Down
388 changes: 312 additions & 76 deletions docs/api/index.html

Large diffs are not rendered by default.

130 changes: 77 additions & 53 deletions docs/api/io.html

Large diffs are not rendered by default.

78 changes: 46 additions & 32 deletions docs/api/resource.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h1 class="title">Module <code>raffiot.resource</code></h1>

from collections import abc
from dataclasses import dataclass
from typing import TypeVar, Generic, Callable, Any, Tuple, List, Iterable, Union
from typing import TypeVar, Generic, Callable, Any, Tuple, List, Iterable

from typing_extensions import final

Expand All @@ -48,7 +48,7 @@ <h1 class="title">Module <code>raffiot.resource</code></h1>
from raffiot._internal import IOTag
from raffiot.io import IO
from raffiot.result import Result, Ok, Errors, Panic
from raffiot.utils import ComputationStatus, MatchError
from raffiot.utils import ComputationStatus, MatchError, TracedException

__all__ = [
&#34;Resource&#34;,
Expand Down Expand Up @@ -178,7 +178,11 @@ <h1 class="title">Module <code>raffiot.resource</code></h1>
return io.pure((f(a), close))
except Exception as exception:
return close_and_merge_failure(
close, Panic(exceptions=[exception], errors=[])
close,
Panic(
exceptions=[TracedException.in_except_clause(exception)],
errors=[],
),
)

return Resource(self.create.flat_map(safe_map))
Expand Down Expand Up @@ -307,7 +311,7 @@ <h1 class="title">Module <code>raffiot.resource</code></h1>
# Panic

def recover(
self, handler: Callable[[List[Exception], List[E]], Resource[R, E, A]]
self, handler: Callable[[List[TracedException], List[E]], Resource[R, E, A]]
) -&gt; Resource[R, E, A]:
&#34;&#34;&#34;
React to panics (the except part of a try-except).
Expand All @@ -316,7 +320,9 @@ <h1 class="title">Module <code>raffiot.resource</code></h1>
&#34;&#34;&#34;
return Resource(self.create.recover(lambda p, e: handler(p, e).create))

def map_panic(self, f: Callable[[Exception], Exception]) -&gt; Resource[R, E, A]:
def map_panic(
self, f: Callable[[TracedException], TracedException]
) -&gt; Resource[R, E, A]:
&#34;&#34;&#34;
Transform the exceptions stored if the computation fails on a panic.
Do nothing otherwise.
Expand Down Expand Up @@ -474,7 +480,7 @@ <h1 class="title">Module <code>raffiot.resource</code></h1>
return Resource(io.error(err))


def errors(*errs: Union[E, Iterable[E]]) -&gt; Resource[R, E, A]:
def errors(*errs: E) -&gt; Resource[R, E, A]:
&#34;&#34;&#34;
Resource creation that always fails on the errors err.
&#34;&#34;&#34;
Expand All @@ -487,9 +493,7 @@ <h1 class="title">Module <code>raffiot.resource</code></h1>
return Resource(io.errors(errs))


def panic(
*exceptions: Union[Exception, Iterable[Exception]], errors: List[E] = None
) -&gt; Resource[R, E, A]:
def panic(*exceptions: TracedException, errors: List[E] = None) -&gt; Resource[R, E, A]:
&#34;&#34;&#34;
Resource creation that always fails with the panic exceptions.
&#34;&#34;&#34;
Expand All @@ -515,7 +519,9 @@ <h1 class="title">Module <code>raffiot.resource</code></h1>
return errors(r.errors)
if isinstance(r, Panic):
return panic(r.exceptions, errors=r.errors)
return panic(MatchError(f&#34;{r} should be a Result&#34;))
return panic(
TracedException.with_stack_trace(MatchError(f&#34;{r} should be a Result&#34;))
)


def from_io_resource(mio: IO[R, E, Resource[R, E, A]]) -&gt; Resource[R, E, A]:
Expand Down Expand Up @@ -568,9 +574,7 @@ <h1 class="title">Module <code>raffiot.resource</code></h1>
return Resource(the_io.map(manager_handler))


def zip(
*rs: Union[Resource[R, E, A], Iterable[Resource[R, E, A]]]
) -&gt; Resource[R, E, List[A]]:
def zip(*rs: Resource[R, E, A]) -&gt; Resource[R, E, List[A]]:
&#34;&#34;&#34;
Transform a list of Resource into a Resource creating a list
of all resources.
Expand Down Expand Up @@ -1004,15 +1008,15 @@ <h2 class="section-title" id="header-functions">Functions</h2>
</details>
</dd>
<dt id="raffiot.resource.errors"><code class="name flex">
<span>def <span class="ident">errors</span></span>(<span>*errs: Union[E, Iterable[E]]) ‑> <a title="raffiot.resource.Resource" href="#raffiot.resource.Resource">Resource</a>[~R, ~E, ~A]</span>
<span>def <span class="ident">errors</span></span>(<span>*errs: E) ‑> <a title="raffiot.resource.Resource" href="#raffiot.resource.Resource">Resource</a>[~R, ~E, ~A]</span>
</code></dt>
<dd>
<div class="desc"><p>Resource creation that always fails on the errors err.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def errors(*errs: Union[E, Iterable[E]]) -&gt; Resource[R, E, A]:
<pre><code class="python">def errors(*errs: E) -&gt; Resource[R, E, A]:
&#34;&#34;&#34;
Resource creation that always fails on the errors err.
&#34;&#34;&#34;
Expand Down Expand Up @@ -1104,7 +1108,9 @@ <h2 class="section-title" id="header-functions">Functions</h2>
return errors(r.errors)
if isinstance(r, Panic):
return panic(r.exceptions, errors=r.errors)
return panic(MatchError(f&#34;{r} should be a Result&#34;))</code></pre>
return panic(
TracedException.with_stack_trace(MatchError(f&#34;{r} should be a Result&#34;))
)</code></pre>
</details>
</dd>
<dt id="raffiot.resource.from_with"><code class="name flex">
Expand Down Expand Up @@ -1183,17 +1189,15 @@ <h2 class="section-title" id="header-functions">Functions</h2>
</details>
</dd>
<dt id="raffiot.resource.panic"><code class="name flex">
<span>def <span class="ident">panic</span></span>(<span>*exceptions: Union[Exception, Iterable[Exception]], errors: List[E] = None) ‑> <a title="raffiot.resource.Resource" href="#raffiot.resource.Resource">Resource</a>[~R, ~E, ~A]</span>
<span>def <span class="ident">panic</span></span>(<span>*exceptions: TracedException, errors: List[E] = None) ‑> <a title="raffiot.resource.Resource" href="#raffiot.resource.Resource">Resource</a>[~R, ~E, ~A]</span>
</code></dt>
<dd>
<div class="desc"><p>Resource creation that always fails with the panic exceptions.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def panic(
*exceptions: Union[Exception, Iterable[Exception]], errors: List[E] = None
) -&gt; Resource[R, E, A]:
<pre><code class="python">def panic(*exceptions: TracedException, errors: List[E] = None) -&gt; Resource[R, E, A]:
&#34;&#34;&#34;
Resource creation that always fails with the panic exceptions.
&#34;&#34;&#34;
Expand Down Expand Up @@ -1341,7 +1345,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
</details>
</dd>
<dt id="raffiot.resource.zip"><code class="name flex">
<span>def <span class="ident">zip</span></span>(<span>*rs: Union[<a title="raffiot.resource.Resource" href="#raffiot.resource.Resource">Resource</a>[R, E, A], Iterable[<a title="raffiot.resource.Resource" href="#raffiot.resource.Resource">Resource</a>[R, E, A]]]) ‑> <a title="raffiot.resource.Resource" href="#raffiot.resource.Resource">Resource</a>[~R, ~E, typing.List[~A]]</span>
<span>def <span class="ident">zip</span></span>(<span>*rs: <a title="raffiot.resource.Resource" href="#raffiot.resource.Resource">Resource</a>[R, E, A]) ‑> <a title="raffiot.resource.Resource" href="#raffiot.resource.Resource">Resource</a>[~R, ~E, typing.List[~A]]</span>
</code></dt>
<dd>
<div class="desc"><p>Transform a list of Resource into a Resource creating a list
Expand All @@ -1354,9 +1358,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def zip(
*rs: Union[Resource[R, E, A], Iterable[Resource[R, E, A]]]
) -&gt; Resource[R, E, List[A]]:
<pre><code class="python">def zip(*rs: Resource[R, E, A]) -&gt; Resource[R, E, List[A]]:
&#34;&#34;&#34;
Transform a list of Resource into a Resource creating a list
of all resources.
Expand Down Expand Up @@ -1543,7 +1545,11 @@ <h2 class="section-title" id="header-classes">Classes</h2>
return io.pure((f(a), close))
except Exception as exception:
return close_and_merge_failure(
close, Panic(exceptions=[exception], errors=[])
close,
Panic(
exceptions=[TracedException.in_except_clause(exception)],
errors=[],
),
)

return Resource(self.create.flat_map(safe_map))
Expand Down Expand Up @@ -1672,7 +1678,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
# Panic

def recover(
self, handler: Callable[[List[Exception], List[E]], Resource[R, E, A]]
self, handler: Callable[[List[TracedException], List[E]], Resource[R, E, A]]
) -&gt; Resource[R, E, A]:
&#34;&#34;&#34;
React to panics (the except part of a try-except).
Expand All @@ -1681,7 +1687,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>
&#34;&#34;&#34;
return Resource(self.create.recover(lambda p, e: handler(p, e).create))

def map_panic(self, f: Callable[[Exception], Exception]) -&gt; Resource[R, E, A]:
def map_panic(
self, f: Callable[[TracedException], TracedException]
) -&gt; Resource[R, E, A]:
&#34;&#34;&#34;
Transform the exceptions stored if the computation fails on a panic.
Do nothing otherwise.
Expand Down Expand Up @@ -2011,7 +2019,11 @@ <h3>Methods</h3>
return io.pure((f(a), close))
except Exception as exception:
return close_and_merge_failure(
close, Panic(exceptions=[exception], errors=[])
close,
Panic(
exceptions=[TracedException.in_except_clause(exception)],
errors=[],
),
)

return Resource(self.create.flat_map(safe_map))</code></pre>
Expand Down Expand Up @@ -2040,7 +2052,7 @@ <h3>Methods</h3>
</details>
</dd>
<dt id="raffiot.resource.Resource.map_panic"><code class="name flex">
<span>def <span class="ident">map_panic</span></span>(<span>self, f: Callable[[Exception], Exception]) ‑> <a title="raffiot.resource.Resource" href="#raffiot.resource.Resource">Resource</a>[~R, ~E, ~A]</span>
<span>def <span class="ident">map_panic</span></span>(<span>self, f: Callable[[TracedException], TracedException]) ‑> <a title="raffiot.resource.Resource" href="#raffiot.resource.Resource">Resource</a>[~R, ~E, ~A]</span>
</code></dt>
<dd>
<div class="desc"><p>Transform the exceptions stored if the computation fails on a panic.
Expand All @@ -2049,7 +2061,9 @@ <h3>Methods</h3>
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def map_panic(self, f: Callable[[Exception], Exception]) -&gt; Resource[R, E, A]:
<pre><code class="python">def map_panic(
self, f: Callable[[TracedException], TracedException]
) -&gt; Resource[R, E, A]:
&#34;&#34;&#34;
Transform the exceptions stored if the computation fails on a panic.
Do nothing otherwise.
Expand Down Expand Up @@ -2099,7 +2113,7 @@ <h3>Methods</h3>
</details>
</dd>
<dt id="raffiot.resource.Resource.recover"><code class="name flex">
<span>def <span class="ident">recover</span></span>(<span>self, handler: Callable[[List[Exception], List[E]], <a title="raffiot.resource.Resource" href="#raffiot.resource.Resource">Resource</a>[R, E, A]]) ‑> <a title="raffiot.resource.Resource" href="#raffiot.resource.Resource">Resource</a>[~R, ~E, ~A]</span>
<span>def <span class="ident">recover</span></span>(<span>self, handler: Callable[[List[TracedException], List[E]], <a title="raffiot.resource.Resource" href="#raffiot.resource.Resource">Resource</a>[R, E, A]]) ‑> <a title="raffiot.resource.Resource" href="#raffiot.resource.Resource">Resource</a>[~R, ~E, ~A]</span>
</code></dt>
<dd>
<div class="desc"><p>React to panics (the except part of a try-except).</p>
Expand All @@ -2109,7 +2123,7 @@ <h3>Methods</h3>
<span>Expand source code</span>
</summary>
<pre><code class="python">def recover(
self, handler: Callable[[List[Exception], List[E]], Resource[R, E, A]]
self, handler: Callable[[List[TracedException], List[E]], Resource[R, E, A]]
) -&gt; Resource[R, E, A]:
&#34;&#34;&#34;
React to panics (the except part of a try-except).
Expand Down
Loading

0 comments on commit 1462ab8

Please sign in to comment.