Repository navigation
Prevent an Outcome to be unwrapped twice. - #11
Conversation
Codecov Report
@@ Coverage Diff @@
## master #11 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 8 8
Lines 196 226 +30
Branches 10 12 +2
=====================================
+ Hits 196 226 +30
Continue to review full report at Codecov.
|
RazerM
left a comment
There was a problem hiding this comment.
When I half-implemented this to try it out, I had
@attr.s(repr=False, init=False, slots=True)
class Outcome(ABC):
_unwrapped = attr.ib(default=False, cmp=False, init=False)
def _set_unwrapped(self):
if self._unwrapped:
raise AlreadyUnwrapped
object.__setattr__(self, '_unwrapped', True)which means
ValueandErrorcan keep@attr.s(frozen=True, repr=False).- We don't need to define
__init__onValueandError
| Error as ErrorBase, Outcome as OutcomeBase, Value as ValueBase | ||
| ) | ||
|
|
||
| from ._util import OutcomeUsedError |
There was a problem hiding this comment.
I don't feel that strongly about it, but I would call it AlreadyUsedError.
| assert repr(v) == "Value(1)" | ||
|
|
||
| with pytest.raises(OutcomeUsedError): | ||
| v.unwrap() |
There was a problem hiding this comment.
We'll need tests that check .send() and .asend() raise OutcomeUsedError too.
|
Ah. I didn't know that you could split frozen and not-frozen simply by subclassing. New commit prepared. |
RazerM
left a comment
There was a problem hiding this comment.
Sorry I should have been clearer with my earlier comments. It's looking good, just a couple more minor changes.
|
|
||
|
|
||
| @attr.s(frozen=True, repr=False) | ||
| @attr.s(repr=False, hash=True) |
There was a problem hiding this comment.
This can be @attr.s(frozen=True, repr=False, slots=True). That is, the same as before this commit but with slots added since that was also added to Outcome.
|
|
||
|
|
||
| @attr.s(frozen=True, repr=False) | ||
| @attr.s(repr=False, hash=True) |
| assert e.error is exc | ||
| with pytest.raises(RuntimeError): | ||
| e.unwrap() | ||
| with pytest.raises(AlreadyUsedError): |
There was a problem hiding this comment.
We're still missing a test that .send() raises AlreadyUnusedError
|
Updated w/ requested changes. |
|
Before I merge, do we need the newsfragment? I pushed some earlier version to PyPI to reserve the name, but as 0.1.0a0, so the next release will be the first release 🤔 |
|
Docs are rarely bad, but it doesn't sound super important either. BTW, has anyone double-checked that these semantics won't break trio? (I mean I think they're probably a good idea, but that doesn't mean I haven't accidentally been naughty in the past :-).) |
|
It's a change with respect to trio.hazmat.Result, thus IMHO it makes sense to keep it. |
|
Good point with respect to |
|
Oops … yes, Trio does fail with this in place. |
Fix #7.