[deprecation] stacklevel tweaks

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changeset62e511de388f
branchdefault
phasepublic
hiddenno
parent revision#bc588b1723a8 Added tag logilab-common-debian-version-0.60.0-1 for changeset 5723c613242e
child revision#e9fc9f452231 merge default heads
files modified by this revision
deprecation.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1367930679 -7200
# Tue May 07 14:44:39 2013 +0200
# Node ID 62e511de388fc18f663f4b25e0bcdbab009cb4b2
# Parent bc588b1723a847261ccaaa2106ed206270f56723
[deprecation] stacklevel tweaks

diff --git a/deprecation.py b/deprecation.py
@@ -78,11 +78,11 @@
1          def decorator(func):
2              message = reason or 'The function "%s" is deprecated'
3              if '%s' in message:
4                  message %= func.func_name
5              def wrapped(*args, **kwargs):
6 -                self.warn(version, message, stacklevel)
7 +                self.warn(version, message, stacklevel+1)
8                  return func(*args, **kwargs)
9              return wrapped
10          return decorator
11 
12      def class_deprecated(self, version=None):
@@ -90,11 +90,11 @@
13              """metaclass to print a warning on instantiation of a deprecated class"""
14 
15              def __call__(cls, *args, **kwargs):
16                  msg = getattr(cls, "__deprecation_warning__",
17                                "%(cls)s is deprecated") % {'cls': cls.__name__}
18 -                self.warn(version, msg)
19 +                self.warn(version, msg, stacklevel=3)
20                  return type.__call__(cls, *args, **kwargs)
21          return metaclass
22 
23      def moved(self, version, modpath, objname):
24          """use to tell that a callable has been moved to a new module.
@@ -127,11 +127,11 @@
25              # old-style class
26              class DeprecatedClass(new_class):
27                  """FIXME: There might be a better way to handle old/new-style class
28                  """
29                  def __init__(self, *args, **kwargs):
30 -                    self.warn(version, message)
31 +                    self.warn(version, message, stacklevel=3)
32                      new_class.__init__(self, *args, **kwargs)
33              return DeprecatedClass
34 
35      def class_moved(self, version, new_class, old_name=None, message=None):
36          """nice wrapper around class_renamed when a class has been moved into