Is there a way to check a function's signature in Python?

后端 未结 4 2384
我寻月下人不归
我寻月下人不归 2021-02-19 08:16

I\'m looking for a way to check the number of arguments that a given function takes in Python. The purpose is to achieve a more robust method of patching my classes for tests.

4条回答
  •  长发绾君心
    2021-02-19 08:28

    inspect.getargspec is deprecated in Python 3. Consider something like:

    import inspect
    len(inspect.signature(foo_func).parameters)
    

提交回复
热议问题