)]}'
{"nova/common/result.py":[{"author":{"_account_id":14070,"name":"Eric Fried","email":"openstack@fried.cc","username":"efried"},"change_message_id":"7ecec9fb310f199730d597d7ec73ea59ca5f56e4","unresolved":false,"context_lines":[{"line_number":15,"context_line":""},{"line_number":16,"context_line":"@total_ordering"},{"line_number":17,"context_line":"class Result(object):"},{"line_number":18,"context_line":""},{"line_number":19,"context_line":"    def __init__(self, value\u003dNone):"},{"line_number":20,"context_line":"        self._value \u003d value"},{"line_number":21,"context_line":""}],"source_content_type":"text/x-python","patch_set":2,"id":"3f79a3b5_971e7b5d","line":18,"updated":"2018-09-26 13:26:47.000000000","message":"This should have a docstring demonstrating how a caller would use it, because that\u0027s not completely obvious. Is it something like:\n\n try:\n     return Result(do_things())\n except Exception as e:\n     return Result(e)\n\nand then somewhere up the stack I get to say:\n\n do_something_with(result)\n\n...and it\u0027ll raise the exception if it\u0027s an exception?\n\nAnd this is better than the way this is normally done (letting the exception percolate up the stack until caught by an except block) because...?","commit_id":"53ce709711c19407fa74191a15ca4cf57129fceb"},{"author":{"_account_id":11604,"name":"sean mooney","email":"smooney@redhat.com","username":"sean-k-mooney"},"change_message_id":"a1206fd4930f5ddb9c805ab9b24d2fd883855cfa","unresolved":false,"context_lines":[{"line_number":15,"context_line":""},{"line_number":16,"context_line":"@total_ordering"},{"line_number":17,"context_line":"class Result(object):"},{"line_number":18,"context_line":""},{"line_number":19,"context_line":"    def __init__(self, value\u003dNone):"},{"line_number":20,"context_line":"        self._value \u003d value"},{"line_number":21,"context_line":""}],"source_content_type":"text/x-python","patch_set":2,"id":"3f79a3b5_8e013307","line":18,"in_reply_to":"3f79a3b5_0ea6d50e","updated":"2018-09-30 14:14:14.000000000","message":"yes ill add some docstrings to provide useage examples.\ni have been off for the last few days so ill get back to this  tomorow.","commit_id":"53ce709711c19407fa74191a15ca4cf57129fceb"},{"author":{"_account_id":4690,"name":"melanie witt","display_name":"melwitt","email":"melwittt@gmail.com","username":"melwitt"},"change_message_id":"7aad9136530066268c6429eee6cb715d7f11fbfe","unresolved":false,"context_lines":[{"line_number":15,"context_line":""},{"line_number":16,"context_line":"@total_ordering"},{"line_number":17,"context_line":"class Result(object):"},{"line_number":18,"context_line":""},{"line_number":19,"context_line":"    def __init__(self, value\u003dNone):"},{"line_number":20,"context_line":"        self._value \u003d value"},{"line_number":21,"context_line":""}],"source_content_type":"text/x-python","patch_set":2,"id":"3f79a3b5_0ea6d50e","line":18,"in_reply_to":"3f79a3b5_971e7b5d","updated":"2018-09-26 15:45:39.000000000","message":"Agree we should have a docstring here with an example. But I think this is just a rough draft looking for early review.\n\nThis came out of an IRC discussion from yesterday [1], where we were talking about how we could store exception objects raised from cells during a scatter-gather call. Currently, we just use a raised_exception_sentinel [2] to signal that a cell raised an exception, and we were talking about how we could have access to the actual raised exception instead of only having a sentinel that tells us an exception was raised. Use case was that tssurya wanted to do something different if the exception was InstanceNotFound, for example [3].\n\n[1] http://eavesdrop.openstack.org/irclogs/%23openstack-nova/%23openstack-nova.2018-09-25.log.html#t2018-09-25T17:30:38\n[2] https://github.com/openstack/nova/blob/ebab3ad/nova/context.py#L445\n[3] https://review.openstack.org/#/c/591658/7/nova/compute/api.py@2327","commit_id":"53ce709711c19407fa74191a15ca4cf57129fceb"},{"author":{"_account_id":14070,"name":"Eric Fried","email":"openstack@fried.cc","username":"efried"},"change_message_id":"7ecec9fb310f199730d597d7ec73ea59ca5f56e4","unresolved":false,"context_lines":[{"line_number":17,"context_line":"class Result(object):"},{"line_number":18,"context_line":""},{"line_number":19,"context_line":"    def __init__(self, value\u003dNone):"},{"line_number":20,"context_line":"        self._value \u003d value"},{"line_number":21,"context_line":""},{"line_number":22,"context_line":"    @property"},{"line_number":23,"context_line":"    def value(self):"}],"source_content_type":"text/x-python","patch_set":2,"id":"3f79a3b5_bcba7e6e","line":20,"updated":"2018-09-26 13:26:47.000000000","message":"This would be more useful if, for exception types, it saved the original context via sys.exc_info(), like save_and_reraise_exception does, and then restored it via six.reraise().","commit_id":"53ce709711c19407fa74191a15ca4cf57129fceb"},{"author":{"_account_id":11604,"name":"sean mooney","email":"smooney@redhat.com","username":"sean-k-mooney"},"change_message_id":"a1206fd4930f5ddb9c805ab9b24d2fd883855cfa","unresolved":false,"context_lines":[{"line_number":17,"context_line":"class Result(object):"},{"line_number":18,"context_line":""},{"line_number":19,"context_line":"    def __init__(self, value\u003dNone):"},{"line_number":20,"context_line":"        self._value \u003d value"},{"line_number":21,"context_line":""},{"line_number":22,"context_line":"    @property"},{"line_number":23,"context_line":"    def value(self):"}],"source_content_type":"text/x-python","patch_set":2,"id":"3f79a3b5_8e78538f","line":20,"in_reply_to":"3f79a3b5_bcba7e6e","updated":"2018-09-30 14:14:14.000000000","message":"im not sure i want to do this in the init but i could add a function decorator that would automatically transform and exception or return value into a Result object.\n\nafter looking into this a bit more\nand finding https://www.python.org/dev/peps/pep-0344/#open-issue-garbage-collection complicates things somewhat.\n\n\nassuming that i was in an except clause\nwould prevent the produce form the result doing something like this\n\ndef mayFail(self, data):\n    if isValid(data):\n        return Result(someFunc(data))\n    else:\n        return Result(VauleError(\"invalid data\"))\n\ni think i know a reasonable solution to this but it will requrie some addtional python 2/3 compatablity code.\n\ni will add specal case code to handel the tuple retruned by\nsys.exe_info  to treat it as an exception and use six.reraise in that case.","commit_id":"53ce709711c19407fa74191a15ca4cf57129fceb"},{"author":{"_account_id":4690,"name":"melanie witt","display_name":"melwitt","email":"melwittt@gmail.com","username":"melwitt"},"change_message_id":"7aad9136530066268c6429eee6cb715d7f11fbfe","unresolved":false,"context_lines":[{"line_number":31,"context_line":"        if self.hasException():"},{"line_number":32,"context_line":"            return False"},{"line_number":33,"context_line":"        else:"},{"line_number":34,"context_line":"            return self._value is not None"},{"line_number":35,"context_line":""},{"line_number":36,"context_line":"    # python 2 compatablity"},{"line_number":37,"context_line":"    __nonzero__ \u003d __bool__"}],"source_content_type":"text/x-python","patch_set":2,"id":"3f79a3b5_ee0ef931","line":34,"updated":"2018-09-26 15:45:39.000000000","message":"I\u0027m trying to think, what would this mean if the method called actually returned None? Then, \"if Result\" would return False. I guess I\u0027m not yet seeing the usefulness of the __bool__ method, because I\u0027m imagining the calling site would look something like:\n\n for cell_uuid, result in results.items():\n     try:\n         # do something with result.value\n     except CellTimeout:\n         # handle timeout behavior\n     except InstanceNotFound:\n         # handle not found behavior","commit_id":"53ce709711c19407fa74191a15ca4cf57129fceb"},{"author":{"_account_id":11604,"name":"sean mooney","email":"smooney@redhat.com","username":"sean-k-mooney"},"change_message_id":"a1206fd4930f5ddb9c805ab9b24d2fd883855cfa","unresolved":false,"context_lines":[{"line_number":31,"context_line":"        if self.hasException():"},{"line_number":32,"context_line":"            return False"},{"line_number":33,"context_line":"        else:"},{"line_number":34,"context_line":"            return self._value is not None"},{"line_number":35,"context_line":""},{"line_number":36,"context_line":"    # python 2 compatablity"},{"line_number":37,"context_line":"    __nonzero__ \u003d __bool__"}],"source_content_type":"text/x-python","patch_set":2,"id":"3f79a3b5_2e533fe0","line":34,"in_reply_to":"3f79a3b5_ee0ef931","updated":"2018-09-30 14:14:14.000000000","message":"the reason for the bool operator is two fold\n\noriginally i wrote hasException in terms of bool then i inverted the relationship.\n\nsecondly the usage pateren you have given is the expected patteren when you expect the produce of the result to fail\ninfrequently e.g. fails less frequently then 1:100 invocations\n\nif you expect the function to return an invalid/error result more frequently then 1:100\n\nyou should consider useing a different pattern at the caller site.\n\nfor cell_uuid, result in results.items():\n     if result\n         # do something with result.value\n     error \u003d result.getException()\n     if type(error) \u003d\u003d CellTimeout: # if you dont want to match derived \n         # handle timeout behavior\n     elif  isinstance(error, InstanceNotFound): # if you do\n         # handle not found behavior\n\nor even a python \"switch\" if there are a lot of distinct types you care about.\n\nfor cell_uuid, result in results.items():\n     cleanup \u003d { CellTimeout: lambda err: pass, ... }\n     if result\n         # do something with result.value\n     error \u003d result.getException()\n     cleanup[type(error)](error)\n\n\nthis alternitive usage patteren is more important in c++ where if are much faster then excptions. pythons if are almost as expencive as exceptions.\n\nthe more compeling case in python for this pattern is not based on how often the producer of the result might fail but rather do you care how it failed or not.\n\nif you just care did the producer of the result succeed\nbecause in the caller you have a primary and fallback algorithim  then the if is the right way to go.\ne.g.\n\ndef someFunc():\n    result \u003d fastPrimaryFunc() # may fail often\n    if not result:\n        result \u003d slowSecondaryFunc() # can fail rarely\n    if result:\n        # do stuff with result\n    else:\n        raise Exception","commit_id":"53ce709711c19407fa74191a15ca4cf57129fceb"}]}
