Fix bad acting classes and 'is_bound_method' check
Change-Id: I5c52e67748402678206919880404e604e4d054ca Closes-Bug: #1498299
This commit is contained in:
parent
84595a0e9a
commit
e17866e4b7
@ -165,7 +165,7 @@ def is_same_callback(callback1, callback2, strict=True):
|
||||
|
||||
def is_bound_method(method):
|
||||
"""Returns if the given method is bound to an object."""
|
||||
return bool(get_method_self(method))
|
||||
return get_method_self(method) is not None
|
||||
|
||||
|
||||
def is_subclass(obj, cls):
|
||||
|
@ -72,6 +72,14 @@ class Class(object):
|
||||
pass
|
||||
|
||||
|
||||
class BadClass(object):
|
||||
def do_something(self):
|
||||
pass
|
||||
|
||||
def __nonzero__(self):
|
||||
return False
|
||||
|
||||
|
||||
class CallableClass(object):
|
||||
def __call__(self, i, j):
|
||||
pass
|
||||
@ -145,6 +153,15 @@ class CallbackEqualityTest(test_base.BaseTestCase):
|
||||
self.assertTrue(reflection.is_same_callback(b.b, c.b, strict=False))
|
||||
|
||||
|
||||
class BoundMethodTest(test_base.BaseTestCase):
|
||||
def test_baddy(self):
|
||||
b = BadClass()
|
||||
self.assertTrue(reflection.is_bound_method(b.do_something))
|
||||
|
||||
def test_static_method(self):
|
||||
self.assertFalse(reflection.is_bound_method(Class.static_method))
|
||||
|
||||
|
||||
class GetCallableNameTest(test_base.BaseTestCase):
|
||||
|
||||
def test_mere_function(self):
|
||||
|
Loading…
Reference in New Issue
Block a user