/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: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

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