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
Can't __repr__
broken promise.
#1
Comments
I need to think about this a bit more. Right now the proxy is intended to always be as transparent as possible -- if you give it work, then any access will deliver and attempt to access the work instead. In the case of something that errors, then the delivery error intentionally is passed upwards. Neither the container nor the proxy have a concept of being broken, they just aren't delivered until the work is successful. What I could conceivably do is write a function called breakable(w), which wraps the work in a try clause, and either introduces a new type to hold any exception (a BrokenPromise perhaps) or simply returns the exception itself as the actual result. A safe_deliver(p) function could then be written to provide a similar wrapper behavior, but from the outside of the promise rather than the inside. A promise_repr(p) (or maybe a log_promise(p) ?) or some such would also possibly be very useful, since you could specifically ask for a representation of the proxy/container without attempting delivery. I definitely see the benefit of such a function. |
commit ac98c7e adds BrokenPromise, breakable, breakable_proxy, breakable_deliver, and promise_repr |
Thanks @obriencj, that was very fast! I still think Part of the problem is that |
As you say, Part of the point of the proxy type is to "hack" in a lazy evaluation that is as transparent as an attribute accessor tries to be. So it really is as though you performed (as in your example) I didn't want to get into overriding some behavior of the proxy but not others, etc. There are the primitive accessors ( |
repr(promises.lazy_proxy(operator.truediv, 2, 0))
gives ZeroDivisionError. I think it would be better to give something like<promises.Proxy (broken: ZeroDivisionError)>
in this case. Logging a promise should not error.Alternatively,
promises.safe_apply
orpromises.safe_repr
could be added.The text was updated successfully, but these errors were encountered: