diff --git a/cranslib/deprecated.py b/cranslib/deprecated.py index 50ee8459..ce2d155e 100644 --- a/cranslib/deprecated.py +++ b/cranslib/deprecated.py @@ -6,6 +6,14 @@ import functools import inspect import sys + +def usage(message, level=2): + """Pour prévenir que ce que tu fais c'est mal et qu'il faut plus le faire comme ça. + ``level`` permet de préciser de combien de crans il faut remonter + pour afficher la ligne responsable de l'erreur""" + warnings.resetwarnings() + warnings.warn(message, category=DeprecationWarning, stacklevel=level) + def deprecated(replace=None): '''This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted @@ -34,12 +42,9 @@ def deprecated(replace=None): return new_func return real_decorator - def module(replace=None): """À appeler dans un module déprécié""" - warnings.resetwarnings() - # On récupère le nom du module appelant la fonction frm = inspect.stack()[1] mod = inspect.getmodule(frm[0]) @@ -55,9 +60,5 @@ def module(replace=None): else: instead = " Use %s instead." % (replace.__name__,) - warnings.warn( - "Call to deprecated module %s.%s" % (module_name, instead), - category=DeprecationWarning, - stacklevel=3 - ) + usage("Call to deprecated module %s.%s" % (module_name, instead), level=4) diff --git a/wiki/action/checkpassword.py b/wiki/action/checkpassword.py index 084fa32b..264d715d 100644 --- a/wiki/action/checkpassword.py +++ b/wiki/action/checkpassword.py @@ -25,4 +25,3 @@ def execute(pagename, request): request.write('OK') else: request.write('Wrong') - #request.write('hello world' + str(u))