Code is obvious. There is nothing novel in this function and could easily be duplicated just by reading Python's docs which explains decorators and the warning API.
Providing the SO link gives a false assumption in regards to licensing.
229 | 229 | """ |
|
230 | 230 | Raise a `DeprecationWarning` when wrapped function/method is called. |
|
231 | 231 | ||
232 | - | Borrowed from https://stackoverflow.com/a/48632082/866026 |
|
232 | + | Usage: |
|
233 | + | ||
234 | + | @deprecated("This method will be removed in version X; use Y instead.") |
|
235 | + | def some_method()" |
|
236 | + | pass |
|
233 | 237 | """ |
|
234 | 238 | ||
235 | - | def _decorator(func): |
|
239 | + | def _wrapper(func): |
|
236 | 240 | @wraps(func) |
|
237 | - | def _func(*args, **kwargs): |
|
241 | + | def _deprecated_func(*args, **kwargs): |
|
238 | 242 | warnings.warn( |
|
239 | - | "'{}' is deprecated. {}".format(func.__name__, message), |
|
243 | + | f"'{func.__name__}' is deprecated. {message}", |
|
240 | 244 | category=DeprecationWarning, |
|
241 | 245 | stacklevel=stacklevel |
|
242 | 246 | ) |
|
243 | 247 | return func(*args, **kwargs) |
|
244 | - | return _func |
|
245 | - | return _decorator |
|
248 | + | return _deprecated_func |
|
249 | + | return _wrapper |
|
246 | 250 | ||
247 | 251 | ||
248 | 252 | def warn_deprecated(message, stacklevel=2): # pragma: no cover |
Files | Coverage |
---|---|
wcmatch | 100.00% |
Project Totals (10 files) | 100.00% |