How do I get the constructor signature for built-in types?

  • Thread starter Steven D'Aprano
  • Start date
S

Steven D'Aprano

The inspect.getargspec and getfullargspec functions allow you to extract
the function call signature for Python functions and methods. This allows
you to work out the constructor signature for pure-Python classes, by
calling inspect.getargspec on the __init__ or __new__ method.

.... def __init__(self, a, b, *args):
.... pass
....ArgSpec(args=['self', 'a', 'b'], varargs='args', keywords=None,
defaults=None)



So far so good. But if the __init__ method is inherited directly from a
built-in, getargspec fails:

.... pass
....Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.2/inspect.py", line 794, in getargspec
getfullargspec(func)
File "/usr/local/lib/python3.2/inspect.py", line 821, in getfullargspec
raise TypeError('{!r} is not a Python function'.format(func))
TypeError: <slot wrapper '__init__' of 'object' objects> is not a Python
function


How do I programmatically get the argument spec of built-in types'
__init__ or __new__ methods?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top