On Nov 3, 8:59 am, Florent Hivert <florent.hiv...@univ-rouen.fr>
wrote:
>       Hi there,
>
>
>
> On Mon, Nov 01, 2010 at 05:30:55AM -0500, Jason Grout wrote:
> > On 11/1/10 12:23 AM, William Stein wrote:
> > >http://sagemath.blogspot.com/2010/10/how-to-referee-sage-trac-tickets...
>
> > Nice.  I'll have more comments later, but I did notice that this:
>
> > from sage.misc.misc import deprecation
> > deprecation("function_name is deprecated, using new_function_name instead!")
>
> > came out in formatting wrong (the second line looks like this in my
> > firefox (3.6.12, osx snow leopard):
>
> > deprecation("function_name is deprecated, using new
>
> > Also, you may want to put in the Sage version number to give people
> > a clue about when to remove the function (see the second argument to
> > deprecation).
>
> Actually there is a more handy tools for this precise purpose namely
> deprecated_function_alias:
>
>         sage: from sage.misc.misc import deprecated_function_alias
>         sage: g = deprecated_function_alias(number_of_partitions,
>         ...     'Sage Version 42.132')
>         sage: g(5)
>         doctest:...: DeprecationWarning: (Since Sage Version 42.132) g is 
> deprecated. Please use number_of_partitions instead.
>         7
>
>     This also works for methods::
>
>         sage: class cls(object):
>         ...      def new_meth(self): return 42
>         ...      old_meth = deprecated_function_alias(new_meth,
>         ...            'Sage Version 42.132')
>         sage: cls().old_meth()
>         doctest:...: DeprecationWarning: (Since Sage Version 42.132) old_meth 
> is deprecated. Please use new_meth instead.
>         42
>
> Cheers,
>
> Florent

Very nice - I wasn't aware of that decorator. I have been working with
a few things regarding decorators in Sage, so I noticed some
shortcomings with deprecated_function_alias:
1) Following Trac #9907, deprecated_function_alias should perhaps be
moved to sage.misc.decorators.
2) Without the wraps-decorator, deprecated_function_alias will seem to
swallow all introspection information on the decorated callable
(actually, sage_wraps should then be used to allow for some Sage-
specific introspection, this in turn requires Trac #9919).
3) Currently, any decorator (even one using sage_wraps) will disrupt
documentation in Sphinx. This is fixed in #9976 and requires no change
in the decorators, however.
Perhaps a Trac should be opened to fix these things under the
assumption of #9907 and #9919, but I don't have time to do it myself
right now (I'm procrastinating terribly as it is)...

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to