Fix parameters of decorated functions

10 views
Skip to first unread message

Aaron S. Meurer

unread,
Feb 25, 2010, 9:46:45 AM2/25/10
to sy...@googlegroups.com
Does anyone know if fixing these things would be possible? I am not to familiar with decorators.

Two aspects of decorated functions annoy me. First off, the function name is changed to the name of the decorated function. The result is that tests that have @XFAIL show up as func_wrapper in bin/test -v. For example:

$./bin/test sympy/solvers/tests/test_ode.py -v
============================= test process starts ==============================
executable: /Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python (2.6.4-final-0)

sympy/solvers/tests/test_ode.py[36]
test_checkodesol ok
test_dsolve_options ok
test_classify_ode ok
func_wrapper f
func_wrapper f
func_wrapper f
[…]

Secondly, the whole slew of information that gathered by source(), help(), and IPython's ? and ?? commands are gathered from the decorated function. Actually, help() gives the correct docstring, but it gives the parameter values of the decorated function. For example, diff() has @vectorize:

In [1]: source(diff)
In file: ./sympy/core/multidimensional.py
def wrapper(*args, **kwargs):
# Get arguments that should be treated multidimensional
[… This is the vectorize function]

Help on function diff in module sympy.core.multidimensional:

In [2]: help(diff)

diff(*args, **kwargs)
Differentiate f with respect to symbols.

[...The docstring is correct, but it should be diff(f, *symbols, **kwargs)]

So can we include something in these decorators to fix these things?

Aaron Meurer

Priit Laes

unread,
Feb 26, 2010, 12:41:10 AM2/26/10
to sy...@googlegroups.com
Ühel kenal päeval, N, 2010-02-25 kell 07:46, kirjutas Aaron S. Meurer:
> Does anyone know if fixing these things would be possible? I am not to
> familiar with decorators.
>
> Two aspects of decorated functions annoy me. First off, the function
> name is changed to the name of the decorated function. The result is
> that tests that have @XFAIL show up as func_wrapper in bin/test -v.
> For example:
>

Nice catch,

Please check out
functools.update_wrapper(...) and functools.wraps(...)

http://docs.python.org/library/functools.html

--
Priit Laes

Aaron S. Meurer

unread,
Feb 26, 2010, 1:06:53 PM2/26/10
to sy...@googlegroups.com
OK, that fixes the XFAIL function name problem, but I still can't get the original function parameters to show up in help(). Any ideas?

Aaron Meurer

> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>

Ronan Lamy

unread,
Feb 26, 2010, 2:13:25 PM2/26/10
to sy...@googlegroups.com
Le vendredi 26 février 2010 à 11:06 -0700, Aaron S. Meurer a écrit :
> OK, that fixes the XFAIL function name problem, but I still can't get the original function parameters to show up in help(). Any ideas?

For that, we'd need to use the decorator package
[http://pypi.python.org/pypi/decorator]. Unlike functools, this is
compatible with 2.4 but I don't know how it fares wrt. the alternative
Python implementations (Jython, IronPython, PyPy). It's pure Python
though, so it *should* work.

Reply all
Reply to author
Forward
0 new messages