1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 __all__ = [ 'deprecated_callable', 'deprecated_usage' ]
19
20 import warnings
21 import inspect
22
24 if inspect.isfunction(obj):
25 return '.'.join((obj.__module__, obj.__name__))
26 if inspect.ismethod(obj):
27 kls = obj.im_class
28 return '.'.join((kls.__module__, kls.__name__, obj.__name__))
29 if isinstance(obj, tuple):
30
31
32 assert len(obj) == 2
33 assert isinstance(obj[0], type)
34 assert isinstance(obj[1], str)
35 assert hasattr(*obj)
36 return '.'.join((obj[0].__module__, obj[0].__name__, obj[1]))
37 return obj.__name__
38
40 if isinstance(obj, tuple):
41 return type(getattr(*obj)).__name__
42 return type(obj).__name__
43
45 assert 1 == (new is not None) + (because is not None)
46 what = callable_type(old)
47 header = "%s %s is deprecated." % (what, callable_name(old))
48 if new is not None:
49 warnings.warn("%s Use %s %s instead." %
50 (header, callable_type(new), callable_name(new)),
51 DeprecationWarning, stacklevel=3)
52 elif because is not None:
53 warnings.warn("%s %s" % (header, because),
54 DeprecationWarning, stacklevel=3)
55
57 warnings.warn("Deprecated usage of %s. %s"
58 % (callable_name(callable), msg),
59 DeprecationWarning, stacklevel=3)
60