Merge "Fixes expose of staticmethod"
This commit is contained in:
@@ -17,6 +17,11 @@ class TestArgSpec(unittest.TestCase):
|
|||||||
def index(self, a, b, c=1, *args, **kwargs):
|
def index(self, a, b, c=1, *args, **kwargs):
|
||||||
return 'Hello, World!'
|
return 'Hello, World!'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@expose()
|
||||||
|
def static_index(a, b, c=1, *args, **kwargs):
|
||||||
|
return 'Hello, World!'
|
||||||
|
|
||||||
return RootController()
|
return RootController()
|
||||||
|
|
||||||
def test_no_decorator(self):
|
def test_no_decorator(self):
|
||||||
@@ -24,6 +29,10 @@ class TestArgSpec(unittest.TestCase):
|
|||||||
actual = util.getargspec(self.controller.index.__func__)
|
actual = util.getargspec(self.controller.index.__func__)
|
||||||
assert expected == actual
|
assert expected == actual
|
||||||
|
|
||||||
|
expected = inspect.getargspec(self.controller.static_index)
|
||||||
|
actual = util.getargspec(self.controller.static_index)
|
||||||
|
assert expected == actual
|
||||||
|
|
||||||
def test_simple_decorator(self):
|
def test_simple_decorator(self):
|
||||||
def dec(f):
|
def dec(f):
|
||||||
return f
|
return f
|
||||||
@@ -32,6 +41,10 @@ class TestArgSpec(unittest.TestCase):
|
|||||||
actual = util.getargspec(dec(self.controller.index.__func__))
|
actual = util.getargspec(dec(self.controller.index.__func__))
|
||||||
assert expected == actual
|
assert expected == actual
|
||||||
|
|
||||||
|
expected = inspect.getargspec(self.controller.static_index)
|
||||||
|
actual = util.getargspec(dec(self.controller.static_index))
|
||||||
|
assert expected == actual
|
||||||
|
|
||||||
def test_simple_wrapper(self):
|
def test_simple_wrapper(self):
|
||||||
def dec(f):
|
def dec(f):
|
||||||
@functools.wraps(f)
|
@functools.wraps(f)
|
||||||
@@ -43,6 +56,10 @@ class TestArgSpec(unittest.TestCase):
|
|||||||
actual = util.getargspec(dec(self.controller.index.__func__))
|
actual = util.getargspec(dec(self.controller.index.__func__))
|
||||||
assert expected == actual
|
assert expected == actual
|
||||||
|
|
||||||
|
expected = inspect.getargspec(self.controller.static_index)
|
||||||
|
actual = util.getargspec(dec(self.controller.static_index))
|
||||||
|
assert expected == actual
|
||||||
|
|
||||||
def test_multiple_decorators(self):
|
def test_multiple_decorators(self):
|
||||||
def dec(f):
|
def dec(f):
|
||||||
@functools.wraps(f)
|
@functools.wraps(f)
|
||||||
@@ -54,6 +71,11 @@ class TestArgSpec(unittest.TestCase):
|
|||||||
actual = util.getargspec(dec(dec(dec(self.controller.index.__func__))))
|
actual = util.getargspec(dec(dec(dec(self.controller.index.__func__))))
|
||||||
assert expected == actual
|
assert expected == actual
|
||||||
|
|
||||||
|
expected = inspect.getargspec(self.controller.static_index)
|
||||||
|
actual = util.getargspec(dec(dec(dec(
|
||||||
|
self.controller.static_index))))
|
||||||
|
assert expected == actual
|
||||||
|
|
||||||
def test_decorator_with_args(self):
|
def test_decorator_with_args(self):
|
||||||
def dec(flag):
|
def dec(flag):
|
||||||
def inner(f):
|
def inner(f):
|
||||||
@@ -66,3 +88,8 @@ class TestArgSpec(unittest.TestCase):
|
|||||||
expected = inspect.getargspec(self.controller.index.__func__)
|
expected = inspect.getargspec(self.controller.index.__func__)
|
||||||
actual = util.getargspec(dec(True)(self.controller.index.__func__))
|
actual = util.getargspec(dec(True)(self.controller.index.__func__))
|
||||||
assert expected == actual
|
assert expected == actual
|
||||||
|
|
||||||
|
expected = inspect.getargspec(self.controller.static_index)
|
||||||
|
actual = util.getargspec(dec(True)(
|
||||||
|
self.controller.static_index))
|
||||||
|
assert expected == actual
|
||||||
|
|||||||
@@ -23,6 +23,12 @@ def getargspec(method):
|
|||||||
|
|
||||||
func_closure = six.get_function_closure(method)
|
func_closure = six.get_function_closure(method)
|
||||||
|
|
||||||
|
# NOTE(sileht): if the closure is None we cannot look deeper,
|
||||||
|
# so return actual argspec, this occurs when the method
|
||||||
|
# is static for example.
|
||||||
|
if func_closure is None:
|
||||||
|
return argspec
|
||||||
|
|
||||||
closure = next(
|
closure = next(
|
||||||
(
|
(
|
||||||
c for c in func_closure if six.callable(c.cell_contents)
|
c for c in func_closure if six.callable(c.cell_contents)
|
||||||
|
|||||||
Reference in New Issue
Block a user