diff --git a/mitogen/parent.py b/mitogen/parent.py index ca57efea..0dfc4f07 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -47,7 +47,6 @@ import termios import textwrap import threading import time -import types import zlib # Absolute imports for <2.5. @@ -490,9 +489,8 @@ def upgrade_router(econtext): def make_call_msg(fn, *args, **kwargs): - if isinstance(fn, types.MethodType) and \ - isinstance(fn.im_self, (type, types.ClassType)): - klass = mitogen.core.to_text(fn.im_self.__name__) + if inspect.ismethod(fn) and inspect.isclass(fn.__self__): + klass = mitogen.core.to_text(fn.__self__.__name__) else: klass = None diff --git a/tests/call_function_test.py b/tests/call_function_test.py index f0074258..eb83dff5 100644 --- a/tests/call_function_test.py +++ b/tests/call_function_test.py @@ -36,7 +36,17 @@ def func_accepts_returns_sender(sender): return sender +class TargetClass: + + offset = 100 + + @classmethod + def add_numbers_with_offset(cls, x, y): + return cls.offset + x + y + + class CallFunctionTest(testlib.RouterMixin, testlib.TestCase): + def setUp(self): super(CallFunctionTest, self).setUp() self.local = self.router.fork() @@ -44,6 +54,12 @@ class CallFunctionTest(testlib.RouterMixin, testlib.TestCase): def test_succeeds(self): self.assertEqual(3, self.local.call(function_that_adds_numbers, 1, 2)) + def test_succeeds_class_method(self): + self.assertEqual( + self.local.call(TargetClass.add_numbers_with_offset, 1, 2), + 103, + ) + def test_crashes(self): exc = self.assertRaises(mitogen.core.CallError, lambda: self.local.call(function_that_fails))