Decorator and utilities for deprecating functions, parameters, and classes with zero boilerplate
Project description
philiprehberger-deprecate
Decorator and utilities for deprecating functions, parameters, and classes with zero boilerplate.
Install
pip install philiprehberger-deprecate
Usage
from philiprehberger_deprecate import deprecated, deprecated_class, deprecated_param
Deprecate a function
@deprecated(remove_in="2.0.0", alternative="new_fetch")
def old_fetch(url: str) -> str:
...
Calling old_fetch() emits:
DeprecationWarning: Function 'old_fetch' is deprecated. Will be removed in 2.0.0. Use 'new_fetch' instead.
Deprecate a parameter
@deprecated_param("color", renamed_to="colour", remove_in="2.0.0")
def draw(shape: str, *, colour: str = "red") -> None:
...
draw(shape="circle", color="blue") # warns and forwards color -> colour
Deprecate a class
@deprecated_class(remove_in="3.0.0", alternative="NewClient")
class OldClient:
def __init__(self, host: str) -> None:
self.host = host
Instantiating OldClient() emits a DeprecationWarning.
API
| Function | Description |
|---|---|
deprecated(remove_in, *, alternative, message) |
Function decorator that emits DeprecationWarning on each call |
deprecated_param(param, *, renamed_to, remove_in) |
Function decorator that warns when a deprecated parameter is passed and optionally maps it to its replacement |
deprecated_class(remove_in, *, alternative, message) |
Class decorator that emits DeprecationWarning on instantiation |
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file philiprehberger_deprecate-0.1.3.tar.gz.
File metadata
- Download URL: philiprehberger_deprecate-0.1.3.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dd2d852012364c94991982b2045fd7e74290cc9fa74733a90dc4f3b01d50767
|
|
| MD5 |
e53c457f768208048d123eaae14d6a44
|
|
| BLAKE2b-256 |
cb79a4b8a5ea7c6041fcbcb6bcbec1d87ef966cf0e2045cef0a4597a0ed422af
|
File details
Details for the file philiprehberger_deprecate-0.1.3-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_deprecate-0.1.3-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1142a4cc3378cb4e2b87a3cb29aa4c9e1a458121b642c259d1ab7e2bf7abc33c
|
|
| MD5 |
d515e185bfc75c6a6b42b3b1f404c950
|
|
| BLAKE2b-256 |
1fa9d9e8bda087e85847424bce189378bdea6adaac2db008d9d52073f69a071d
|