~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/symbol_versioning.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-12 16:20:00 UTC
  • mto: This revision was merged to the branch mainline in revision 1871.
  • Revision ID: john@arbash-meinel.com-20060712162000-c8cfe629b012e0bb
Move ignores into a file of their own, make DEFAULT_IGNORE a deprecated list. Create deprecated_list in symbol versioning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
"""
22
22
 
23
23
__all__ = ['deprecated_function',
 
24
           'deprecated_list',
24
25
           'deprecated_method',
25
26
           'DEPRECATED_PARAMETER',
26
27
           'deprecated_passed',
145
146
    decorated_callable.__module__ = callable.__module__
146
147
    decorated_callable.__name__ = callable.__name__
147
148
    decorated_callable.is_deprecated = True
 
149
 
 
150
 
 
151
def deprecated_list(deprecation_version, variable_name,
 
152
                    initial_value, extra=None):
 
153
    """Create a list that warns when modified
 
154
 
 
155
    :param deprecation_version: something like zero_nine
 
156
    :param initial_value: The contents of the list
 
157
    :param variable_name: This allows better warnings to be printed
 
158
    :param extra: Extra info to print when printing a warning
 
159
    """
 
160
 
 
161
    subst_text = 'Modifying %s' % (variable_name,)
 
162
    msg = deprecation_version % (subst_text,)
 
163
    if extra:
 
164
        msg += ' ' + extra
 
165
 
 
166
    class _DeprecatedList(list):
 
167
        __doc__ = list.__doc__ + msg
 
168
 
 
169
        is_deprecated = True
 
170
 
 
171
        def _warn_deprecated(self, func, *args, **kwargs):
 
172
            warn(msg, DeprecationWarning, stacklevel=3)
 
173
            return func(self, *args, **kwargs)
 
174
            
 
175
        def append(self, obj):
 
176
            """appending to %s is deprecated""" % (variable_name,)
 
177
            return self._warn_deprecated(list.append, obj)
 
178
 
 
179
        def insert(self, index, obj):
 
180
            """inserting to %s is deprecated""" % (variable_name,)
 
181
            return self._warn_deprecated(list.insert, index, obj)
 
182
 
 
183
        def extend(self, iterable):
 
184
            """extending %s is deprecated""" % (variable_name,)
 
185
            return self._warn_deprecated(list.extend, iterable)
 
186
 
 
187
        def remove(self, value):
 
188
            """removing from %s is deprecated""" % (variable_name,)
 
189
            return self._warn_deprecated(list.remove, value)
 
190
 
 
191
        def pop(self, index=None):
 
192
            """pop'ing from from %s is deprecated""" % (variable_name,)
 
193
            if index:
 
194
                return self._warn_deprecated(list.pop, index)
 
195
            else:
 
196
                # Can't pass None
 
197
                return self._warn_deprecated(list.pop)
 
198
 
 
199
    return _DeprecatedList(initial_value)