MCPcopy Create free account
hub / github.com/numpy/numpy / _Deprecate

Class _Deprecate

numpy/lib/utils.py:104–169  ·  view source on GitHub ↗

Decorator class to deprecate old functions. Refer to `deprecate` for details. See Also -------- deprecate

Source from the content-addressed store, hash-verified

102
103
104class _Deprecate:
105 """
106 Decorator class to deprecate old functions.
107
108 Refer to `deprecate` for details.
109
110 See Also
111 --------
112 deprecate
113
114 """
115
116 def __init__(self, old_name=None, new_name=None, message=None):
117 self.old_name = old_name
118 self.new_name = new_name
119 self.message = message
120
121 def __call__(self, func, *args, **kwargs):
122 """
123 Decorator call. Refer to ``decorate``.
124
125 """
126 old_name = self.old_name
127 new_name = self.new_name
128 message = self.message
129
130 if old_name is None:
131 old_name = func.__name__
132 if new_name is None:
133 depdoc = "`%s` is deprecated!" % old_name
134 else:
135 depdoc = "`%s` is deprecated, use `%s` instead!" % \
136 (old_name, new_name)
137
138 if message is not None:
139 depdoc += "\n" + message
140
141 @functools.wraps(func)
142 def newfunc(*args, **kwds):
143 warnings.warn(depdoc, DeprecationWarning, stacklevel=2)
144 return func(*args, **kwds)
145
146 newfunc.__name__ = old_name
147 doc = func.__doc__
148 if doc is None:
149 doc = depdoc
150 else:
151 lines = doc.expandtabs().split('\n')
152 indent = _get_indent(lines[1:])
153 if lines[0].lstrip():
154 # Indent the original first line to let inspect.cleandoc()
155 # dedent the docstring despite the deprecation notice.
156 doc = indent * ' ' + doc
157 else:
158 # Remove the same leading blank lines as cleandoc() would.
159 skip = len(lines[0]) + 1
160 for line in lines[1:]:
161 if len(line) > indent:

Callers 2

deprecateFunction · 0.85
deprecate_with_docFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected