En Sat, 01 Oct 2011 12:13:45 -0300, julian bilcke
<julian.bil...@gmail.com> escribió:
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. [...]
>>> 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)
I'm afraid there is no way; this kind of introspection does not work for
functions written in C. The function itself usually has a generic
signature resembling (*args, **kw), and its parameters are usually
unpacked calling a suitable variant of PyArg_ParseXXX. The information
about the number and type of expected arguments is encoded in its 'format'
parameter, and is not stored anywhere.
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list