Welcome, guest | Sign In | My Account | Store | Cart
#!/usr/bin/env python

import functools
import warnings
warnings.simplefilter("once", category=(PendingDeprecationWarning, DeprecationWarning))

def deprecate(msg, klass=PendingDeprecationWarning):
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            warnings.warn(msg, klass, stacklevel=2)
            return func(*args, **kwargs)
        return wrapper
    return decorator


if __name__ == "__main__":
    @deprecate("This function will be deprecated in the future. Use new_function().")
    def old_function(a, b):
        new_function(a, b, 0)

    def new_function(a, b, c):
        print(a+b+c)

    old_function(1, 2)

Diff to Previous Revision

--- revision 1 2013-08-23 13:20:21
+++ revision 2 2013-08-23 13:24:40
@@ -15,7 +15,7 @@
 
 
 if __name__ == "__main__":
-    @deprecate("This function will be deprecated in the future. User new_function().")
+    @deprecate("This function will be deprecated in the future. Use new_function().")
     def old_function(a, b):
         new_function(a, b, 0)
 

History