/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: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
The methods here allow for api symbol versioning.
20
20
"""
21
21
 
22
 
from __future__ import absolute_import
23
 
 
24
22
__all__ = ['deprecated_function',
25
23
           'deprecated_in',
26
24
           'deprecated_list',
71
69
    """Generate an automatic deprecation string for a_callable.
72
70
 
73
71
    :param a_callable: The callable to substitute 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.
 
72
    :param deprecation_version: A deprecation format warning string. This
 
73
        should have a single %s operator in it. a_callable will be turned into
 
74
        a nice python symbol and then substituted into deprecation_version.
77
75
    """
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:
 
76
    if getattr(a_callable, '__self__', None) is not None:
84
77
        symbol = "%s.%s.%s" % (a_callable.__self__.__class__.__module__,
85
78
                               a_callable.__self__.__class__.__name__,
86
 
                               a_callable.__name__
87
 
                               )
 
79
                               a_callable.__name__)
 
80
    elif getattr(a_callable, '__qualname__', None) is not None and '<' not in a_callable.__qualname__:
 
81
        symbol = "%s.%s" % (a_callable.__module__,
 
82
                            a_callable.__qualname__)
 
83
    else:
 
84
        symbol = "%s.%s" % (a_callable.__module__,
 
85
                            a_callable.__name__)
88
86
    return deprecation_version % symbol
89
87
 
90
88
 
99
97
            from . import trace
100
98
            trace.mutter_callsite(4, "Deprecated function called")
101
99
            warn(deprecation_string(callable, deprecation_version),
102
 
                DeprecationWarning, stacklevel=2)
 
100
                 DeprecationWarning, stacklevel=2)
103
101
            return callable(*args, **kwargs)
104
102
        _populate_decorated(callable, deprecation_version, "function",
105
103
                            decorated_function)
135
133
                                       callable.__name__
136
134
                                       )
137
135
            trace.mutter_callsite(4, "Deprecated method called")
138
 
            warn(deprecation_version % symbol, DeprecationWarning, stacklevel=2)
 
136
            warn(deprecation_version %
 
137
                 symbol, DeprecationWarning, stacklevel=2)
139
138
            return callable(self, *args, **kwargs)
140
139
        _populate_decorated(callable, deprecation_version, "method",
141
140
                            decorated_method)
159
158
    # def __init__(self, bad, other)
160
159
    # def __init__(self, **kwargs)
161
160
    # RBC 20060116
162
 
    return not parameter_value is DEPRECATED_PARAMETER
 
161
    return parameter_value is not DEPRECATED_PARAMETER
163
162
 
164
163
 
165
164
def _decorate_docstring(callable, deprecation_version, label,
171
170
    if len(docstring_lines) == 0:
172
171
        decorated_callable.__doc__ = deprecation_version % ("This " + label)
173
172
    elif len(docstring_lines) == 1:
174
 
        decorated_callable.__doc__ = (callable.__doc__
175
 
                                    + "\n"
176
 
                                    + "\n"
177
 
                                    + deprecation_version % ("This " + label)
178
 
                                    + "\n")
 
173
        decorated_callable.__doc__ = (
 
174
            callable.__doc__ + "\n" + "\n" +
 
175
            deprecation_version % ("This " + label) + "\n")
179
176
    else:
180
177
        spaces = len(docstring_lines[-1])
181
178
        new_doc = callable.__doc__
214
211
    is_deprecated = True
215
212
 
216
213
    def __init__(self,
217
 
        deprecation_version,
218
 
        variable_name,
219
 
        initial_value,
220
 
        advice,
221
 
        ):
 
214
                 deprecation_version,
 
215
                 variable_name,
 
216
                 initial_value,
 
217
                 advice,
 
218
                 ):
222
219
        """Create a dict that warns when read or modified.
223
220
 
224
221
        :param deprecation_version: string for the warning format to raise,
318
315
    """
319
316
    def cleanup():
320
317
        if filter:
321
 
            warnings.filters.remove(filter)
 
318
            try:
 
319
                warnings.filters.remove(filter)
 
320
            except (ValueError, IndexError):
 
321
                pass
322
322
    return cleanup
323
323
 
324
324