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

Method __call__

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

Decorator call. Refer to ``decorate``.

(self, func, *args, **kwargs)

Source from the content-addressed store, hash-verified

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:
162 break
163 skip += len(line) + 1
164 doc = doc[skip:]
165 depdoc = textwrap.indent(depdoc, ' ' * indent)
166 doc = '\n\n'.join([depdoc, doc])
167 newfunc.__doc__ = doc
168
169 return newfunc
170
171
172def _get_indent(lines):

Callers

nothing calls this directly

Calls 5

_get_indentFunction · 0.85
expandtabsMethod · 0.80
lstripMethod · 0.80
splitMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected