Skip to main content

Decorator and utilities for deprecating functions, parameters, and classes with zero boilerplate

Project description

philiprehberger-deprecate

Tests PyPI version Last updated

Decorator and utilities for deprecating functions, parameters, and classes with zero boilerplate.

Installation

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

Development

pip install -e .
python -m pytest tests/ -v

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

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.7.tar.gz (5.2 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.7-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_deprecate-0.1.7.tar.gz
Algorithm Hash digest
SHA256 d01aa02cc1aa06d8570572c32c3b84db4fc5582ca997e854e72c8359fa14ea48
MD5 375f08065434008bfd9a08f14e3d074d
BLAKE2b-256 5d0c37c2a4a26a12185dedaf450520cfb7f4fe387055e0cf8b07d80c36ad095e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_deprecate-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 24872efbd89936d937cc66d350ea6f9e93dca51c4adbdd724d86611fdcfb82c9
MD5 ae7fab134d9589358e43602f0b91c998
BLAKE2b-256 f88a7a9f67e0b09d90776cdfadd3f3a2fd83e1297f2b9350aeea9f16f9dd1ebc

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