[deprecated] On peut fournir la fonction à utiliser en remplacement de celle dépréciée. (ou un random message)
This commit is contained in:
parent
691ce584bc
commit
9221fb8db0
2 changed files with 23 additions and 13 deletions
|
@ -211,7 +211,7 @@ exit
|
||||||
for switch in self.switch :
|
for switch in self.switch :
|
||||||
self.configure_switch(switch)
|
self.configure_switch(switch)
|
||||||
|
|
||||||
@deprecated
|
@deprecated("Tous les switchs possèdent une authentification radius.")
|
||||||
def configure_chbre(self,chbre) :
|
def configure_chbre(self,chbre) :
|
||||||
""" Recontigure la chambre fournie chambre.
|
""" Recontigure la chambre fournie chambre.
|
||||||
Déprécié. Tous les switchs possèdent une authentification radius."""
|
Déprécié. Tous les switchs possèdent une authentification radius."""
|
||||||
|
|
|
@ -4,18 +4,28 @@
|
||||||
import warnings
|
import warnings
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
def deprecated(func):
|
def deprecated(replace=None):
|
||||||
'''This is a decorator which can be used to mark functions
|
'''This is a decorator which can be used to mark functions
|
||||||
as deprecated. It will result in a warning being emitted
|
as deprecated. It will result in a warning being emitted
|
||||||
when the function is used.'''
|
when the function is used.'''
|
||||||
|
|
||||||
@functools.wraps(func)
|
if replace == None:
|
||||||
def new_func(*args, **kwargs):
|
instead = ""
|
||||||
warnings.warn_explicit(
|
elif isinstance(replace, str) or isinstance(replace, unicode):
|
||||||
"Call to deprecated function {}.".format(func.__name__),
|
instead = " " + replace
|
||||||
category=DeprecationWarning,
|
else:
|
||||||
filename=func.func_code.co_filename,
|
instead = " Use %s instead." % (replace.__name__,)
|
||||||
lineno=func.func_code.co_firstlineno + 1
|
|
||||||
)
|
def real_decorator(func):
|
||||||
return func(*args, **kwargs)
|
"""Nested because a decorator with a parameter has to be coded this way"""
|
||||||
return new_func
|
@functools.wraps(func)
|
||||||
|
def new_func(*args, **kwargs):
|
||||||
|
warnings.warn_explicit(
|
||||||
|
"Call to deprecated function %s.%s" % (func.__name__, instead),
|
||||||
|
category=DeprecationWarning,
|
||||||
|
filename=func.func_code.co_filename,
|
||||||
|
lineno=func.func_code.co_firstlineno + 1
|
||||||
|
)
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
return new_func
|
||||||
|
return real_decorator
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue