Skip to main content

A Wrapper for functions, class objects and methods for deprecating keyword parameters

Project description

Deprecated Params

PyPI version PyPI - Downloads License: MIT

Inspired after python's warning.deprecated wrapper, deprecated_params is made to serve the single purpose of deprecating parameter names to warn users about incoming changes as well as retaining typehinting.

How to Deprecate Parameters

Parameters should be keyword arguments, not positional, Reason for this implementation is that in theory you should've already planned an alternative approach to an argument you wish to deprecate.

from deprecated_params import deprecated_params

@deprecated_params(['x'])
def func(y, *, x:int = 0):
    pass

# DeprecationWarning: Parameter "x" is deprecated
func(None, x=20)

# NOTE: **kw is accepted but also you could put down more than one 
# parameter if needed...
@deprecated_params(['foo'], {"foo":"foo was removed in ... don't use it"}, display_kw=False)
class MyClass:
    def __init__(self, spam:object, **kw):
        self.spam = spam
        self.foo = kw.get("foo", None)

# DeprecationWarning: foo was removed in ... don't use it
mc = MyClass("spam", foo="X")

Why I wrote Deprecated Params

I got tired of throwing random warnings in my code and wanted something cleaner that didn't interfere with a function's actual code and didn't blind anybody trying to go through it. Contributors and Reviewers should be able to utilize a library that saves them from this problems. After figuring out that the functionality I was looking for didn't exist I took the opportunity to do so.

Deprecated Params used in real-world Examples

Deprecated-params is now used with two of my own libraries by default.

  • aiothreading

    • Originally aiothreading had it's own wrapper but I split it off to this library along with a rewrite after finding out that parameter names were not showing up ides such as vs-code. The rewrite felt a bit bigger and knowing that users would want to utilize this concept in other places was how this library ultimately got started.
    • Lots of interior changes were made and with many arguments being suddenly dropped to increase the performance, the best solution was to warn developers to stop using certain parameters as they will be deleted in the future.
  • aiocallback

    • Same situation as aiothreading but I decided to buy users more time due to how fast some releases were going and it also allowed me to experiemnt with this library to ensure that it was working correctly.

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

deprecated_params-0.1.5.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deprecated_params-0.1.5-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file deprecated_params-0.1.5.tar.gz.

File metadata

  • Download URL: deprecated_params-0.1.5.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for deprecated_params-0.1.5.tar.gz
Algorithm Hash digest
SHA256 31ea3f256c5924b8d9cba17fc03f1cf20d63c7619902678e2f7193a0aff9c86d
MD5 d61455854e62f5758d7f73d1bc3ee480
BLAKE2b-256 f4769109e364b5b8d2ac2c975c125f0c19a9eafdf6b75290c7c68e9afbc19fe7

See more details on using hashes here.

File details

Details for the file deprecated_params-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for deprecated_params-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a75c93d4e1e71699d9799bf2c99d3844ce36b2b8ea0733990d182d285716131e
MD5 879b32eea5e83d85194f84cf5277d93c
BLAKE2b-256 cf943944fe1a2a95ee7ee5baea442bfeeb6290b7422b049df7d810b50f480733

See more details on using hashes here.

Supported by

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