关注本主题:允许用户“扩展” API 功能
class Inspector:
def __init__(self, passedFunc):
self.passedFunc = passedFunc
def __call__(self, *args, **kwargs):
# Inspector needs to generate a list of arguments of the passed function and print them in *correct* order
# now how to generate a list of arguments using data from both ''args' and 'kwargs'?
# the user might keep default argument values, in which case both will be None,
# he might only use args, in which case it is easy,
# but he might also use kwargs, in which case I don't see how to generate a list with correct order of arguments
# and he might use all 3 from above together
# I found this solution for when only default arguments are used
if args == () and kwargs == {}: args = self.passedFunc.__defaults__
print args
@Inspector
def exampleFunc(value=0, otherValue=3):
pass
exampleFunc()
如何为所有场景生成正确的订单参数列表?