Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions six.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions test_six.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down