Skip to main content

A Tool for Depreating (Keyword) Arguments for Python Functions

Project description

deprecate-kwargs

formatting pytest

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)

Uploaded Source

Built Distribution

deprecate_kwargs-0.0.1-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page