/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 breezy/symbol_versioning.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
    """Generate an automatic deprecation string for a_callable.
72
72
 
73
73
    :param a_callable: The callable to substitute into deprecation_version.
74
 
    :param deprecation_version: A deprecation format warning string. This
75
 
        should have a single %s operator in it. a_callable will be turned into
76
 
        a nice python symbol and then substituted into deprecation_version.
 
74
    :param deprecation_version: A deprecation format warning string. This should
 
75
        have a single %s operator in it. a_callable will be turned into a nice
 
76
        python symbol and then substituted into deprecation_version.
77
77
    """
78
 
    if getattr(a_callable, '__self__', None) is not None:
 
78
    # We also want to handle old-style classes, in particular exception, and
 
79
    # they don't have an im_class attribute.
 
80
    if getattr(a_callable, 'im_class', None) is None:
 
81
        symbol = "%s.%s" % (a_callable.__module__,
 
82
                            a_callable.__name__)
 
83
    else:
79
84
        symbol = "%s.%s.%s" % (a_callable.__self__.__class__.__module__,
80
85
                               a_callable.__self__.__class__.__name__,
81
 
                               a_callable.__name__)
82
 
    elif getattr(a_callable, '__qualname__', None) is not None and '<' not in a_callable.__qualname__:
83
 
        symbol = "%s.%s" % (a_callable.__module__,
84
 
                            a_callable.__qualname__)
85
 
    else:
86
 
        symbol = "%s.%s" % (a_callable.__module__,
87
 
                            a_callable.__name__)
 
86
                               a_callable.__name__
 
87
                               )
88
88
    return deprecation_version % symbol
89
89
 
90
90
 
99
99
            from . import trace
100
100
            trace.mutter_callsite(4, "Deprecated function called")
101
101
            warn(deprecation_string(callable, deprecation_version),
102
 
                 DeprecationWarning, stacklevel=2)
 
102
                DeprecationWarning, stacklevel=2)
103
103
            return callable(*args, **kwargs)
104
104
        _populate_decorated(callable, deprecation_version, "function",
105
105
                            decorated_function)
135
135
                                       callable.__name__
136
136
                                       )
137
137
            trace.mutter_callsite(4, "Deprecated method called")
138
 
            warn(deprecation_version %
139
 
                 symbol, DeprecationWarning, stacklevel=2)
 
138
            warn(deprecation_version % symbol, DeprecationWarning, stacklevel=2)
140
139
            return callable(self, *args, **kwargs)
141
140
        _populate_decorated(callable, deprecation_version, "method",
142
141
                            decorated_method)
160
159
    # def __init__(self, bad, other)
161
160
    # def __init__(self, **kwargs)
162
161
    # RBC 20060116
163
 
    return parameter_value is not DEPRECATED_PARAMETER
 
162
    return not parameter_value is DEPRECATED_PARAMETER
164
163
 
165
164
 
166
165
def _decorate_docstring(callable, deprecation_version, label,
172
171
    if len(docstring_lines) == 0:
173
172
        decorated_callable.__doc__ = deprecation_version % ("This " + label)
174
173
    elif len(docstring_lines) == 1:
175
 
        decorated_callable.__doc__ = (
176
 
            callable.__doc__ + "\n" + "\n" +
177
 
            deprecation_version % ("This " + label) + "\n")
 
174
        decorated_callable.__doc__ = (callable.__doc__
 
175
                                    + "\n"
 
176
                                    + "\n"
 
177
                                    + deprecation_version % ("This " + label)
 
178
                                    + "\n")
178
179
    else:
179
180
        spaces = len(docstring_lines[-1])
180
181
        new_doc = callable.__doc__
213
214
    is_deprecated = True
214
215
 
215
216
    def __init__(self,
216
 
                 deprecation_version,
217
 
                 variable_name,
218
 
                 initial_value,
219
 
                 advice,
220
 
                 ):
 
217
        deprecation_version,
 
218
        variable_name,
 
219
        initial_value,
 
220
        advice,
 
221
        ):
221
222
        """Create a dict that warns when read or modified.
222
223
 
223
224
        :param deprecation_version: string for the warning format to raise,
317
318
    """
318
319
    def cleanup():
319
320
        if filter:
320
 
            try:
321
 
                warnings.filters.remove(filter)
322
 
            except (ValueError, IndexError):
323
 
                pass
 
321
            warnings.filters.remove(filter)
324
322
    return cleanup
325
323
 
326
324