From 8445bfaf84cdee72d9506f905070397dc6cb0f2b Mon Sep 17 00:00:00 2001 From: caorantaoyao Date: Tue, 11 Aug 2026 05:17:18 +0800 Subject: [PATCH] fix: issue #342 --- six.py | 4 ++++ test_six.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/six.py b/six.py index a0a9abb8..b6c56b11 100644 --- a/six.py +++ b/six.py @@ -561,6 +561,10 @@ def callable(obj): return any("__call__" in klass.__dict__ for klass in type(obj).__mro__) +def is_bound_method(obj): + return callable(obj) and isinstance(obj, types.MethodType) + + if PY3: def get_unbound_function(unbound): return unbound diff --git a/test_six.py b/test_six.py index 8890c0e3..952d73ed 100644 --- a/test_six.py +++ b/test_six.py @@ -459,6 +459,26 @@ def method(self): assert not six.callable("string") +def test_is_bound_method(): + class X(object): + def method(self): + pass + + @classmethod + def class_method(cls): + pass + + def plain_function(): + pass + + assert six.is_bound_method(X().method) is True + assert six.is_bound_method(X.class_method) is True + assert six.is_bound_method(X.method) is False + assert six.is_bound_method(plain_function) is False + assert six.is_bound_method(test_is_bound_method) is False + assert six.is_bound_method(len) is False + + def test_create_bound_method(): class X(object): pass