Deprecating Code

exception metatools.deprecate.CallingDeprecatedWarning[source]
exception metatools.deprecate.AttributeRenamedWarning[source]
exception metatools.deprecate.FunctionRenamedWarning[source]
exception metatools.deprecate.ModuleRenamedWarning[source]
metatools.deprecate.renamed_attr[source]

Proxy for renamed attributes (or methods) on classes.

Getting and setting values will be redirected to the provided name, and warnings will be issues every time.

E.g.:

>>> class Example(object):
... 
...     new_value = 'something'
...     old_value = renamed_attr('new_value')
...     
...     def new_func(self, a, b):
...         return a + b
...         
...     old_func = renamed_attr('new_func')

>>> e = Example()

>>> e.old_value = 'else'
# AttributeRenamedWarning: Example.old_value renamed to new_value

>>> e.old_func(1, 2)
# AttributeRenamedWarning: Example.old_func renamed to new_func
3
metatools.deprecate.renamed_func(func, name=None, module=None)[source]

Proxy for renamed functions.

Parameters:
  • func – The function to actually call.
  • name (str) – The name that this used to be called; for warnings.
  • module (str) – The module that this used to be in; for warnings.
Returns:

A function which calls the original, and omits a warning.

E.g.:

>>> def new(a, b):
...     return a + b

>>> old = renamed_func(new, 'old', __name__)

>>> old(1, 2)
# FunctionRenamedWarning: example.old renamed to example.new
3
metatools.deprecate.module_renamed(new_name)[source]

Replace the current module with the one found at the given name.

Issues a ModuleRenamedWarning.

For example,

new.py:

>>> def func():
...     print "Hello from %s!" % __name__

old.py:

>>> from metatools.deprecate import module_renamed
>>> module_renamed('new')

use.py:

>>> from old import func
# ModuleRenamedWarning: old was renamed to new
>>> func()
Hello from new!
metatools.deprecate.deprecate(func)[source]

Wrap a function so that it will issue a deprecation warning.

>>> @deprecate
... def old_func():
...     print "Hello!"
... 
>>> old_func()
# CallingDeprecatedWarning: example.old_func has been deprecated
Hello!
Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.