/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/symbol_versioning.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
           'zero_eighteen',
40
40
           'zero_ninety',
41
41
           'zero_ninetyone',
 
42
           'zero_ninetytwo',
42
43
           ]
43
44
 
44
45
from warnings import warn
59
60
zero_eighteen = "%s was deprecated in version 0.18."
60
61
zero_ninety = "%s was deprecated in version 0.90."
61
62
zero_ninetyone = "%s was deprecated in version 0.91."
 
63
zero_ninetytwo = "%s was deprecated in version 0.92."
62
64
 
63
65
 
64
66
def set_warning_method(method):
84
86
        have a single %s operator in it. a_callable will be turned into a nice
85
87
        python symbol and then substituted into deprecation_version.
86
88
    """
 
89
    # We also want to handle old-style classes, in particular exception, and
 
90
    # they don't have an im_class attribute.
87
91
    if getattr(a_callable, 'im_class', None) is None:
88
92
        symbol = "%s.%s" % (a_callable.__module__,
89
93
                            a_callable.__name__)
114
118
 
115
119
def deprecated_method(deprecation_version):
116
120
    """Decorate a method so that use of it will trigger a warning.
 
121
 
 
122
    To deprecate a static or class method, use 
 
123
 
 
124
        @staticmethod
 
125
        @deprecated_function
 
126
        def ...
117
127
    
118
128
    To deprecate an entire class, decorate __init__.
119
129
    """
123
133
        
124
134
        def decorated_method(self, *args, **kwargs):
125
135
            """This is the decorated method."""
126
 
            symbol = "%s.%s.%s" % (self.__class__.__module__,
127
 
                                   self.__class__.__name__,
128
 
                                   callable.__name__
129
 
                                   )
 
136
            if callable.__name__ == '__init__':
 
137
                symbol = "%s.%s" % (self.__class__.__module__,
 
138
                                    self.__class__.__name__,
 
139
                                    )
 
140
            else:
 
141
                symbol = "%s.%s.%s" % (self.__class__.__module__,
 
142
                                       self.__class__.__name__,
 
143
                                       callable.__name__
 
144
                                       )
130
145
            warn(deprecation_version % symbol, DeprecationWarning, stacklevel=2)
131
146
            return callable(self, *args, **kwargs)
132
147
        _populate_decorated(callable, deprecation_version, "method",