Skip to content

Commit

Permalink
Merge pull request #7 from SomberNight/hashable_exc
Browse files Browse the repository at this point in the history
make CodeMessageError hashable
  • Loading branch information
Neil committed Sep 25, 2018
2 parents f779092 + 4d1763d commit 81139fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions aiorpcx/jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ def __eq__(self, other):
return (isinstance(other, self.__class__) and
self.code == other.code and self.message == other.message)

def __hash__(self):
# overridden to make the exception hashable
# see https://bugs.python.org/issue28603
return hash((self.code, self.message))

@classmethod
def invalid_args(cls, message):
return cls(JSONRPC.INVALID_ARGS, message)
Expand Down
6 changes: 5 additions & 1 deletion tests/test_jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from aiorpcx import *
from aiorpcx.jsonrpc import Response
from aiorpcx.jsonrpc import Response, CodeMessageError
from util import RaiseTest, assert_RPCError, assert_ProtocolError
from random import shuffle

Expand Down Expand Up @@ -79,6 +79,10 @@ class MyProtocol(JSONRPC):
MyProtocol._request_args({})


def test_exception_is_hashable():
hash(CodeMessageError(0, '')) # see if raises


# ENCODING


Expand Down

0 comments on commit 81139fc

Please sign in to comment.