~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/symbol_versioning.py

  • Committer: Martin Pool
  • Date: 2006-02-01 12:24:35 UTC
  • mfrom: (1534.4.32 branch-formats)
  • mto: This revision was merged to the branch mainline in revision 1553.
  • Revision ID: mbp@sourcefrog.net-20060201122435-53f3efb1b5749fe1
[merge] branch-formats branch, and reconcile changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
The methods here allow for api symbol versioning.
21
21
"""
22
22
 
23
 
__all__ = ['warn', 'set_warning_method', 'zero_seven']
 
23
__all__ = ['deprecated_function',
 
24
           'deprecated_method',
 
25
           'DEPRECATED_PARAMETER',
 
26
           'deprecated_passed',
 
27
           'warn', 'set_warning_method', 'zero_seven',
 
28
           'zero_eight',
 
29
           ]
24
30
 
25
31
from warnings import warn
26
32
 
27
33
 
 
34
DEPRECATED_PARAMETER = "A deprecated parameter marker."
28
35
zero_seven = "%s was deprecated in version 0.7."
29
36
zero_eight = "%s was deprecated in version 0.8."
30
37
 
54
61
            symbol = "%s.%s" % (callable.__module__, 
55
62
                                callable.__name__
56
63
                                )
57
 
            warn(deprecation_version % symbol, DeprecationWarning)
 
64
            warn(deprecation_version % symbol, DeprecationWarning, stacklevel=2)
58
65
            return callable(*args, **kwargs)
59
66
        _populate_decorated(callable, deprecation_version, "function",
60
67
                            decorated_function)
77
84
                                   self.__class__.__name__,
78
85
                                   callable.__name__
79
86
                                   )
80
 
            warn(deprecation_version % symbol, DeprecationWarning)
 
87
            warn(deprecation_version % symbol, DeprecationWarning, stacklevel=2)
81
88
            return callable(self, *args, **kwargs)
82
89
        _populate_decorated(callable, deprecation_version, "method",
83
90
                            decorated_method)
85
92
    return method_decorator
86
93
 
87
94
 
 
95
def deprecated_passed(parameter_value):
 
96
    """Return True if parameter_value was used."""
 
97
    # FIXME: it might be nice to have a parameter deprecation decorator. 
 
98
    # it would need to handle positional and *args and **kwargs parameters,
 
99
    # which means some mechanism to describe how the parameter was being
 
100
    # passed before deprecation, and some way to deprecate parameters that
 
101
    # were not at the end of the arg list. Thats needed for __init__ where
 
102
    # we cannot just forward to a new method name.I.e. in the following
 
103
    # examples we would want to have callers that pass any value to 'bad' be
 
104
    # given a warning - because we have applied:
 
105
    # @deprecated_parameter('bad', zero_seven)
 
106
    #
 
107
    # def __init__(self, bad=None)
 
108
    # def __init__(self, bad, other)
 
109
    # def __init__(self, **kwargs)
 
110
    # RBC 20060116
 
111
    return not parameter_value is DEPRECATED_PARAMETER
 
112
 
 
113
 
88
114
def _decorate_docstring(callable, deprecation_version, label,
89
115
                        decorated_callable):
90
116
    docstring_lines = callable.__doc__.split('\n')