Skip to content

remove reference to value/error when unwrapping outcome #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

graingert
Copy link
Member

No description provided.

@graingert graingert force-pushed the invalid-objects-on-unwrap branch from 7c22bcb to 20c75bf Compare March 22, 2025 11:36
@graingert graingert force-pushed the invalid-objects-on-unwrap branch from 49cd098 to 4d40df0 Compare March 22, 2025 11:44
@TeamSpen210
Copy link
Contributor

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.

@graingert
Copy link
Member Author

could just call it InvalidatingOutcome, InvalidatingError and InvalidatingValue

@TeamSpen210
Copy link
Contributor

A parallel class hierarchy seems problematic, they'd be incompatible with the current ones. More thinking like unwrap_and_clear(), that's all we need.

@CoolCat467
Copy link
Member

Would using a weak reference not be acceptable?

@graingert
Copy link
Member Author

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

Copy link

@richardsheridan richardsheridan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

try:
return f'Error({self.error!r})'
except AttributeError:
return 'Error(<DEAD>)'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be Error(<AlreadyUsed>)?

def _unwrap_error(self) -> BaseException:
try:
v = self.error
except AttributeError:
Copy link

@richardsheridan richardsheridan Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use descriptors to transmute any late access to self.error or self.value directly to AlreadyUsedError?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe __getattr__?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make them private attributes, add a property?

@RazerM
Copy link
Member

RazerM commented Apr 4, 2025

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 AlreadyUsedError over AttributeError.

The way I've always used outcome is to only .unwrap() or .send(), so I would be fine with an outcome 2.0 that doesn't have the attributes, but I know Trio does use them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants