Issues a DeprecationWarning, adds warning to `old_name`'s docstring, rebinds ``old_name.__name__`` and returns the new function object. This function may also be used as a decorator. Parameters ---------- func : function The function to be deprecated. old_n
(*args, **kwargs)
| 184 | |
| 185 | |
| 186 | def deprecate(*args, **kwargs): |
| 187 | """ |
| 188 | Issues a DeprecationWarning, adds warning to `old_name`'s |
| 189 | docstring, rebinds ``old_name.__name__`` and returns the new |
| 190 | function object. |
| 191 | |
| 192 | This function may also be used as a decorator. |
| 193 | |
| 194 | Parameters |
| 195 | ---------- |
| 196 | func : function |
| 197 | The function to be deprecated. |
| 198 | old_name : str, optional |
| 199 | The name of the function to be deprecated. Default is None, in |
| 200 | which case the name of `func` is used. |
| 201 | new_name : str, optional |
| 202 | The new name for the function. Default is None, in which case the |
| 203 | deprecation message is that `old_name` is deprecated. If given, the |
| 204 | deprecation message is that `old_name` is deprecated and `new_name` |
| 205 | should be used instead. |
| 206 | message : str, optional |
| 207 | Additional explanation of the deprecation. Displayed in the |
| 208 | docstring after the warning. |
| 209 | |
| 210 | Returns |
| 211 | ------- |
| 212 | old_func : function |
| 213 | The deprecated function. |
| 214 | |
| 215 | Examples |
| 216 | -------- |
| 217 | Note that ``olduint`` returns a value after printing Deprecation |
| 218 | Warning: |
| 219 | |
| 220 | >>> olduint = np.deprecate(np.uint) |
| 221 | DeprecationWarning: `uint64` is deprecated! # may vary |
| 222 | >>> olduint(6) |
| 223 | 6 |
| 224 | |
| 225 | """ |
| 226 | # Deprecate may be run as a function or as a decorator |
| 227 | # If run as a function, we initialise the decorator class |
| 228 | # and execute its __call__ method. |
| 229 | |
| 230 | if args: |
| 231 | fn = args[0] |
| 232 | args = args[1:] |
| 233 | |
| 234 | return _Deprecate(*args, **kwargs)(fn) |
| 235 | else: |
| 236 | return _Deprecate(*args, **kwargs) |
| 237 | |
| 238 | |
| 239 | def deprecate_with_doc(msg): |