remove reference to value/error when unwrapping outcome, and add .peek() method#45
remove reference to value/error when unwrapping outcome, and add .peek() method#45graingert wants to merge 15 commits intopython-trio:mainfrom
.peek() method#45Conversation
7c22bcb to
20c75bf
Compare
20c75bf to
08b08df
Compare
49cd098 to
4d40df0
Compare
|
This might need to be a new method for backwards compatibility, since the attributes are public, users would be able to still read them after unwrapping. Unless we're fine with that breaking change. |
|
could just call it InvalidatingOutcome, InvalidatingError and InvalidatingValue |
|
A parallel class hierarchy seems problematic, they'd be incompatible with the current ones. More thinking like |
|
Would using a weak reference not be acceptable? |
I think that would be more complicated and it would be odd that unwrapped values are sometimes there sometimes not and not everything can be weakref'd |
richardsheridan
left a comment
There was a problem hiding this comment.
I'm +1 on "just delete the attribute on unwrap". It's understandable and minimal and the only issue is backwards compatibility, so I'd say slap a unwrap_and_clear() method on version 1.4.0 and make a 2.0.0 release for the cleaner implementation to free more users from refcycles.
|
I'm -1 on deleting public attributes during unwrap. I don't like that accessing an attribute/property may raise, but if we go that route then I'd much prefer The way I've always used outcome is to only |
|
I was off sick and didn't have time to focus on this PR, I'd like to pick it back up again |
856bb3c to
6a1174b
Compare
6a1174b to
47e6abd
Compare
add types e.error unwraps
47e6abd to
2606efb
Compare
62a114b to
fdbd48d
Compare
|
I do wonder, since this is a breaking change, maybe it'd be better to make it entirely breaking - change the properties to |
CoolCat467
left a comment
There was a problem hiding this comment.
I don't see any immediate issues. Would raise the possibility of sharing peek and return, return/unwrap just being peek and then unset, but as is is still fine.
|
ok let's add peek |
.peek()
.peek().peek() method
|
the trio test suite (and typecheck) pass unmodified when run with this branch python-trio/trio#3385 |
|
Just realized codecov isn't working: https://github.com/python-trio/outcome/actions/runs/21510106791/job/61974795642?pr=45#step:4:658 I'll submit a PR to fix that, but IMO it doesn't really matter. EDIT: see #48 |
|
I like this API, but there is still the fundamental issue that you can't raise the same exception object twice because it has only one traceback. (That's why Two options I see:
|
|
What I was meaning with the |
I don't want to break the API too much because trio depends on "outcome" with no version range |
I've gone for option 2, |
| x = fn(*args) | ||
| x = outcome.capture(fn, *args).peek() | ||
|
|
||
| """ |
There was a problem hiding this comment.
I don't really get the use case for peek in a world where we aren't using it to rename the properties...
There was a problem hiding this comment.
rename the properties?
I'm happy to remove peek but I'd want everyone to agree
There was a problem hiding this comment.
From what I understood, @TeamSpen210 mentioned them to force existing users to use .peek() s.t. existing users of .value and .error get typecheckers warning about it. (and my reading was that they would return an error value, not raise)
Since compatibility with existing Trio (given we don't have an upper bound) is probably more important, we can't do that -- in which case, having them basically duplicates the properties. Not sure if that's what @CoolCat467 / @oremanj read from earlier comments.
There was a problem hiding this comment.
Yeah that was my thought, they'd act the same as the property, but be a different name so you get instant feedback (type checker or runtime exception).
There was a problem hiding this comment.
yeah we can't do this as it would break compatibility with trio which does not have a maximum version constraint on outcome
There was a problem hiding this comment.
If we're not removing the properties, no real reason to have peek - main reason I proposed a method is to communicate that it's now a mutating operation, not something you can do multiple times, but if the properties exist that's just misleading.
There was a problem hiding this comment.
We need the properties because they are used by trio
|
I've made an alternative approach that's fully backwards compatible #49 |
Fixes #47
currently unwraping exceptions leaves a refcycle that keeps the entire traceback and any locals alive. This PR resolves that by clearing the error field when the Error is unwrapped.
For the previous behaviour of Value (eg in trio) if you receive a large bytes object in a Value that bytes object stays alive long after it's needed. This PR resolves that by clearing the value field when the Value is unwrapped.
this is a breaking change and should probably be released with a major version bump, eg outcome==2.0.0