From f7abf4655019784e94ecd04d7bd88b796cded754 Mon Sep 17 00:00:00 2001 From: Daniel STAN Date: Sat, 13 Apr 2013 14:55:32 +0200 Subject: [PATCH] Rajout d'un decorateur "deprecated" --- lib/deprecated.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/deprecated.py diff --git a/lib/deprecated.py b/lib/deprecated.py new file mode 100644 index 00000000..36870887 --- /dev/null +++ b/lib/deprecated.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import warnings +import functools + +def deprecated(func): + '''This is a decorator which can be used to mark functions + as deprecated. It will result in a warning being emitted + when the function is used.''' + + @functools.wraps(func) + def new_func(*args, **kwargs): + warnings.warn_explicit( + "Call to deprecated function {}.".format(func.__name__), + category=DeprecationWarning, + filename=func.func_code.co_filename, + lineno=func.func_code.co_firstlineno + 1 + ) + return func(*args, **kwargs) + return new_func