A Tool for Depreating (Keyword) Arguments for Python Functions
Project description
deprecate-kwargs
A Tool for Depreating (Keyword) Arguments for Python Functions.
A decorator is implemented to deprecate old kwargs in a function, with signature and docstring modified accordingly. Instead of replacing the old kwargs with new ones, this decorator makes old and new kwargs both available, with warnings raised when old kwargs are passed.
Usage Example
>>> from deprecate_kwargs import deprecate_kwargs
>>> @deprecate_kwargs([["new_arg_1", "old_arg_1"], ["new_arg_2", "old_arg_2"]])
>>> def some_func(old_arg_1: int, old_arg_2: int):
>>> return old_arg_1 + old_arg_2
>>> some_func.__signature__
<Signature (new_arg_1:int, new_arg_2:int)>
>>> some_func(10, 20)
30
>>> some_func(new_arg_1=10, new_arg_2=20)
30
>>> some_func(old_arg_1=10, old_arg_2=20)
UserWarning: key word argument "old_arg_1" is deprecated, use "new_arg_1" instead
UserWarning: key word argument "old_arg_2" is deprecated, use "new_arg_2" instead
30
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
deprecate_kwargs-0.0.1.tar.gz
(3.0 kB
view hashes)
Built Distribution
Close
Hashes for deprecate_kwargs-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 323122c27de304b8cccaa70172d6d1c12447db775e16109bb7a091cfb6dc2aaa |
|
MD5 | d5465ba562c8e4a41f3ea0860929e625 |
|
BLAKE2b-256 | a893726a855f7a2cd60aedb191af2004dc6cf53f6a664e5bff3aadc73b6cff04 |