How to inspect slot wrappers arguments in Python?

julian bilcke julian.bilcke at gmail.com
Sat Oct 1 11:13:45 EDT 2011


Hi,

I would like to get the list of parameters I need to initialize an AST node.

I'm trying to use the `inspect` module, however it seems I can't use it on a
built-in (native?) class, or else I misunderstood.

I'm using Python 2.7 and tried with Python 3.2.

This is working:

    >>> import inspect
    >>> class C:
    ...     def __init__(a,b=4):
    ...         self.sum = a + b
    ...
    >>> inspect.getargspec(C.__init__)
    ArgSpec(args=['a', 'b'], varargs=None, keywords=None, defaults=(4,))

This is not working:

    >>> import inspect
    >>> import ast
    >>> inspect.getargspec(ast.If.__init__)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py",
line 813, in getargspec
        raise TypeError('{!r} is not a Python function'.format(func))
    TypeError: <slot wrapper '__init__' of '_ast.AST' objects> is not a
Python function

I am wondering if there is another way to get these parameters
automatically? (ie. without compiling myself a dict)

Regards,
J. Bilcke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111001/59b777f0/attachment.html>


More information about the Python-list mailing list