PythonRemoteServer icon indicating copy to clipboard operation
PythonRemoteServer copied to clipboard

Possible RecursionError in KeywordResult._handle_return_value()

Open tw39124-1 opened this issue 6 years ago • 0 comments

KeywordResult._handle_return_value() calls itself as part of a list-comprehension if ret does not get handled by the initial if-statements:

def _handle_return_value(self, ret):
    if isinstance(ret, (str, unicode, bytes)):
        return self._handle_binary_result(ret)
    if isinstance(ret, (int, long, float)):
        return ret
    if isinstance(ret, Mapping):
        return dict((self._str(key), self._handle_return_value(value))
                    for key, value in ret.items())
    try:
        return [self._handle_return_value(item) for item in ret]
    except TypeError:
        return self._str(ret)

However, in this case ret is an object provided by a library, which happens to return itself when __getitem__ is called. _handle_return_value then enters an infinite recursion, which eventually causes the interpreter to raise a RecursionError. Should the list comprehension be inside an if-clause which checks that the object is actually a list-like object?

To get around this for now I am pickling and base64-encoding the object to a string and returning that, but that means I have to decode and de-pickle it back into an object on the client side. It would be nice if I didn't have to do this and could just return an object from my remote keyword without this issue.

tw39124-1 avatar Dec 11 '19 16:12 tw39124-1