Skip to content

Commit

Permalink
Replace _intf to __rid__ for identifying interface object (#194)
Browse files Browse the repository at this point in the history
* Fix hashing for dict contain list

* Fix linter error

* Remove _rintf, and use __rid__
  • Loading branch information
oeway authored Oct 7, 2021
1 parent f4ea8a7 commit 1836f0e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion javascript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imjoy-rpc",
"version": "0.3.28",
"version": "0.3.29",
"description": "Remote procedure calls for ImJoy.",
"module": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion python/imjoy_rpc/VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.3.28"
"version": "0.3.29"
}
3 changes: 2 additions & 1 deletion python/imjoy_rpc/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,10 @@ def _decode(self, a_object, with_promise):
if isinstance(a_object, dict) and a_object.get("_rintf"):
# make the dict hashable
if isinstance(b_object, dict):
b_object["_rintf"] = a_object.get("_rintf")
if not isinstance(b_object, dotdict):
b_object = dotdict(b_object)
# __rid__ is used for hashing the object for removing it afterwards
b_object.__rid__ = a_object.get("_rintf")

self._object_weakmap[b_object] = a_object.get("_rintf")
return b_object
12 changes: 10 additions & 2 deletions python/imjoy_rpc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ class dotdict(dict): # pylint: disable=invalid-name
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__

def __setattr__(self, name, value):
"""Set the attribute."""
# Make an exception for __rid__
if name == "__rid__":
super().__setattr__("__rid__", value)
else:
super().__setitem__(name, value)

def __hash__(self):
"""Return the hash."""
if "_rintf" in self and type(self["_rintf"]) is str:
return hash(self["_rintf"] + _hash_id)
if self.__rid__ and type(self.__rid__) is str:
return hash(self.__rid__ + _hash_id)

# FIXME: This does not address the issue of inner list
return hash(tuple(sorted(self.items())))
Expand Down

0 comments on commit 1836f0e

Please sign in to comment.