You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment, the classes in aioresult do not override the __str__() and __repr__() methods. That means that the string representation is, to put it mildly, not helpful:
<aioresult._src.ResultCapture object at 0x0000014DA6513B80>
You can't just log out the ResultBase.result() return value because it can raise an exception if the task is not done or has raised, and even ResultBase.exception() will throw if the task is not done. I think those are good design choices but they're annoying here. I suggest that the string representation could look like this:
These aren't real ways that you could construct a ResultCapture object but that's OK. I don't think there's any point including the other two fields (e.g. ResultCapture(is_done=True, result="elephant", exception=None)).
Another consideration is that ResultCapture equality is not overridden so is based only on the ID of the object. This is for the best because even two ResultCapture for the same routine and arguments that finish in the same way still represent two different runs of that routine. But it means that, from a purity point of view, the string representation should include the ... at 0x0000014DA6513B80 part. I think that, in practice, this would be more annoying than helpful.
All the above works for ResultBase including Future. But for ResultCapture we may want to include the routine and arguments, but not always. So I suggest allowing an alternative format string to include it; we could use "#" to match the character for alternative format of numbers. The output would look like this:
classResultBase:
# ... current code ...def_routine_str(self):
return""# Overridden in ResultCapturedef__format__(self, format_spec):
ifformat_specnotin ("", "#"):
raiseValueError("ResultBase format must be '' or '#'")
routine_str=self._routine_str() ifformat_spec=="#"else""ifnotself.is_done():
result_str="is_done=False"elifself._exceptionisnotNone:
result_str="exception="+repr(self._exception)
else:
result_str="result="+str(self._result)
returnf"{type(self).__name__}({routine_str}{result_str})"def__repr__(self):
returnself.__format__("")
classResultCapture:
# ... current code ...def_routine_str(self):
"""Allows the alternative format to include routine and arguments; used in __format__."""returnf"routine={self.routine.__qualname__}, args={self.args}, "
The text was updated successfully, but these errors were encountered:
At the moment, the classes in aioresult do not override the
__str__()
and__repr__()
methods. That means that the string representation is, to put it mildly, not helpful:You can't just log out the
ResultBase.result()
return value because it can raise an exception if the task is not done or has raised, and evenResultBase.exception()
will throw if the task is not done. I think those are good design choices but they're annoying here. I suggest that the string representation could look like this:These aren't real ways that you could construct a
ResultCapture
object but that's OK. I don't think there's any point including the other two fields (e.g.ResultCapture(is_done=True, result="elephant", exception=None)
).Another consideration is that
ResultCapture
equality is not overridden so is based only on the ID of the object. This is for the best because even twoResultCapture
for the same routine and arguments that finish in the same way still represent two different runs of that routine. But it means that, from a purity point of view, the string representation should include the... at 0x0000014DA6513B80
part. I think that, in practice, this would be more annoying than helpful.All the above works for
ResultBase
includingFuture
. But forResultCapture
we may want to include the routine and arguments, but not always. So I suggest allowing an alternative format string to include it; we could use"#"
to match the character for alternative format of numbers. The output would look like this:This code would do it:
The text was updated successfully, but these errors were encountered: