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
Nice catch,
Please check out
functools.update_wrapper(...) and functools.wraps(...)
http://docs.python.org/library/functools.html
--
Priit Laes
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.
>
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.