Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fec4d82

Browse files
committed
Allow exporting non-hashable function
Instead of hashing the function object, hash its name instead. There is no particular reason to consider a function instance and its name as two independent entities in the context of the same object. As a bonus, this means you can now replace your methods on the fly and the next call will reach the new one. I am not sure why you would want to do that though.
1 parent fdac478 commit fec4d82

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

zerorpc/core.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,15 @@ def __init__(self, channel, methods=None, name=None, context=None,
6868

6969
@staticmethod
7070
def _filter_methods(cls, self, methods):
71-
if hasattr(methods, '__getitem__'):
71+
if isinstance(methods, dict):
7272
return methods
73-
server_methods = set(getattr(self, k) for k in dir(cls) if not
74-
k.startswith('_'))
73+
server_methods = set(k for k in dir(cls) if not k.startswith('_'))
7574
return dict((k, getattr(methods, k))
76-
for k in dir(methods)
77-
if (callable(getattr(methods, k))
78-
and not k.startswith('_')
79-
and getattr(methods, k) not in server_methods
80-
))
75+
for k in dir(methods)
76+
if callable(getattr(methods, k))
77+
and not k.startswith('_')
78+
and k not in server_methods
79+
)
8180

8281
@staticmethod
8382
def _extract_name(methods):

0 commit comments

Comments
 (0)