Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#7515 closed enhancement (fixed)

Improved deprecation and renaming of function and methods

Reported by: hivert Owned by: hivert
Priority: major Milestone: sage-4.3
Component: misc Keywords: deprecation:
Cc: combinat Merged in: sage-4.3.alpha1
Authors: Florent Hivert Reviewers: Nathann Cohen
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

Along the cleanup of combinat, a lot of methods and function get renamed. It is painfull to write backward compatibility aliases. The patch given here should make it easier. I take also the chance to add a version optional argument to deprecation to store and print in which version of sage the method/function was deprecated.

Here is an excerpt from the doc:

        sage: from sage.misc.misc import deprecated_function_alias
        sage: g = deprecated_function_alias(number_of_partitions,
        ...     'Sage Version 42.132, Release Date: 5123-04-01')
        sage: g(5)
        doctest:1: DeprecationWarning: (Since Sage Version 42.132, Release Date: 5123-04-01) g is deprecated. Please use number_of_partitions instead.
        7

This also works for methods:

        sage: from sage.misc.misc import deprecated_method_alias
        sage: class cls(object):
        ...      def new_meth(self): return 42
        ...      old_meth = deprecated_method_alias(new_meth,
        ...            'Sage Version 42.132, Release Date: 5123-04-01')
        sage: cls().old_meth()
        doctest:...: DeprecationWarning: (Since Sage Version 42.132, Release Date: 5123-04-01) old_meth is deprecated. Please use new_meth instead.
        42

Attachments (1)

trac_7515_method_alias_decorator-fh.patch (14.7 KB) - added by hivert 11 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 11 years ago by hivert

  • Status changed from new to needs_review

comment:2 Changed 11 years ago by hivert

Adressed William comments on sage-devel.

Changed 11 years ago by hivert

comment:3 Changed 11 years ago by hivert

Updated patch to remark on sage-devel (i.e. just put the version of deprecation, without the date). Reday for review.

comment:4 follow-up: Changed 11 years ago by ncohen

  • Status changed from needs_review to positive_review

No problem with this one... Extremely useful :-)

Do you think one should create a ticket saying "replace all the deprecation warning using deprecated_function_alias whenever possible" ?

Firsdt, it would shorten Sage's code, plus everybody would see this is how we should set functions as deprecated instead of using the old method... I "copy" things very often in Sage's code, and if I am not working around an example of this, you can be sure I'd do it the other way :-)

Positive review, thanks for your work !

Nathann

comment:5 in reply to: ↑ 4 Changed 11 years ago by hivert

Replying to ncohen:

No problem with this one... Extremely useful :-)

Do you think one should create a ticket saying "replace all the deprecation warning using deprecated_function_alias whenever possible" ?

This would be surely a good idea, but I'm not sure I wan't to volunteer to do this one right now. There are a lot of deprecated things in sage. Here is a rough evaluation:

tomahawk-*/devel/sage-main $ grep deprecat **/*.py **/*.pyx | wc
   1228   13940  168762

So I'm opening the ticket but I currently don't accept it.

Cheers,

Florent

comment:6 Changed 11 years ago by ncohen

Perhaps it is possible to script it in emacs.... :-)

comment:7 Changed 11 years ago by mhansen

  • Merged in set to sage-4.3.alpha1
  • Resolution set to fixed
  • Reviewers set to Nathann Cohen
  • Status changed from positive_review to closed

Looks good to me.

comment:8 Changed 11 years ago by mvngu

  • Summary changed from Improved deprecation and renaming of function and methods. to Improved deprecation and renaming of function and methods
Note: See TracTickets for help on using tickets.