mirror of https://github.com/scrapy/scrapy.git
Fixes #368: Support functools.partial in scrapy.utils.python.get_func_args()
This commit is contained in:
parent
f18ac02987
commit
09c3f53693
|
|
@ -1,3 +1,4 @@
|
|||
import functools
|
||||
import operator
|
||||
import unittest
|
||||
from itertools import count
|
||||
|
|
@ -174,12 +175,14 @@ class UtilsPythonTestCase(unittest.TestCase):
|
|||
pass
|
||||
|
||||
a = A(1, 2, 3)
|
||||
partial_f1 = functools.partial(f1, None)
|
||||
cal = Callable()
|
||||
|
||||
self.assertEqual(get_func_args(f1), ['a', 'b', 'c'])
|
||||
self.assertEqual(get_func_args(f2), ['a', 'b', 'c'])
|
||||
self.assertEqual(get_func_args(A), ['a', 'b', 'c'])
|
||||
self.assertEqual(get_func_args(a.method), ['a', 'b', 'c'])
|
||||
self.assertEqual(get_func_args(partial_f1), ['a', 'b', 'c'])
|
||||
self.assertEqual(get_func_args(cal), ['a', 'b', 'c'])
|
||||
self.assertEqual(get_func_args(object), [])
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import re
|
|||
import inspect
|
||||
import weakref
|
||||
import errno
|
||||
from functools import wraps
|
||||
from functools import partial, wraps
|
||||
from sgmllib import SGMLParser
|
||||
|
||||
|
||||
|
|
@ -156,6 +156,8 @@ def get_func_args(func, stripself=False):
|
|||
return get_func_args(func.__func__, True)
|
||||
elif inspect.ismethoddescriptor(func):
|
||||
return []
|
||||
elif isinstance(func, partial):
|
||||
return get_func_args(func.func)
|
||||
elif hasattr(func, '__call__'):
|
||||
if inspect.isroutine(func):
|
||||
return []
|
||||
|
|
|
|||
Loading…
Reference in New Issue