Skip to main content

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

philiprehberger_deprecate-0.1.1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

philiprehberger_deprecate-0.1.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_deprecate-0.1.1.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_deprecate-0.1.1.tar.gz
Algorithm Hash digest
SHA256 452db3993fe752d408fca663441a318f4393d2f00b7b9c45a9a30904c1ce4d70
MD5 979b51d9a9a1796f6338fc9bb7560f0f
BLAKE2b-256 9cd797672ed53d1a04dcadbbd03ab6ddc4549a3ddbcf4620996493605a8cf870

See more details on using hashes here.

File details

Details for the file philiprehberger_deprecate-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_deprecate-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 41e1ddc2c2e72defd53ef98db918b41786a0d70bafbb11aca2da8da61258bdc1
MD5 b8807c71a7709ed12356cec199a8c4bd
BLAKE2b-256 d88b13c68cd63ac2275ced0de523ac4dfe840748e29946c24a97c4c09f8a18c4

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