12.07.2015 Views

Sage Developer's Guide - Mirrors

Sage Developer's Guide - Mirrors

Sage Developer's Guide - Mirrors

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Sage</strong> Developer’s <strong>Guide</strong>, Release 6.1.1Note: Before removing any functionality, you should keep a deprecation warning in place for at least one year (ifpossible). The deprecation must include the trac ticket number where it was introduced.For example, let’s say you run across the following while working on a module in the <strong>Sage</strong> library:class Foo(<strong>Sage</strong>Object):def terrible_idea(self):return 1def bad_name(self):return 1def f(self, weird_keyword=True):return self._f_implementation(weird_keyword=weird_keyword)def _f_implementation(self, weird_keyword=True):return 1You note that the terrible_idea() method does not make any sense, and should be removed altogether. Youopen the trac ticket number 3333 (say), and replace the code with:def terrible_idea(self):from sage.misc.superseded import deprecationdeprecation(3333, ’You can just call f() instead’)return 1Later, you come up with a much better name for the second method. You open the trac ticket number 4444, and replaceit with:def much_better_name(self):return 1bad_name = deprecated_function_alias(4444, much_better_name)Finally, you like the f() method name but you don’t like the weird_keyword name. You fix this by opening thetrac ticket 5555, and replacing it with:@rename_keyword(deprecation=5555, weird_keyword=’nice_keyword’)def f(self, nice_keyword=True):return self._f_implementation(nice_keyword=nice_keyword)def _f_implementation(self, nice_keyword=True):return 1Note that the underscore-method _f_implementation is, by convention, not something that ought to be used byothers. So we do not need to deprecate anything when we change it.Now, any user that still relies on the deprecated functionality will be informed that this is about to change, yet thedeprecated commands still work. With all necessary imports, the final result looks like this:sage: from sage.misc.superseded import deprecation, deprecated_function_aliassage: from sage.misc.decorators import rename_keywordsage: class Foo(<strong>Sage</strong>Object):....:....: def terrible_idea(self):....: deprecation(3333, ’You can just call f() instead’)....: return 1....:....: def much_better_name(self):....: return 1....:4.2. Coding in Python for <strong>Sage</strong> 39

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!