Registry / testing / pydeprecate

pydeprecate

JSON →
library0.11.0pypypi✓ verified 24d ago

pyDeprecate is a lightweight Python library (version 0.7.0) for managing function and class deprecations with zero dependencies. It provides automatic call forwarding to replacement functions, argument mapping between old and new APIs, and configurable warning controls to prevent log spam. It is actively maintained and designed to help library maintainers evolve APIs while maintaining backward compatibility.

pip install pydeprecate
INSTALL
IMPORT
SIG · PYDEPRECATE
P
pydeprecate
testingpythonv0.11.0
Install
1.5s avg
Import
135ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.11.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.144s · 18.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.126s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

deprecated
from deprecate import deprecated
deprecated_class
from deprecate import deprecated_class
deprecated_instance
from deprecate import deprecated_instance
void
from deprecate import void
Helper function to silence IDE warnings about unused parameters in deprecated functions when a 'target' is specified.

This quickstart demonstrates how to use the `@deprecated` decorator with and without a `target` function. When a `target` is provided, calls are forwarded to the new function, and the `void` helper silences IDE warnings. When `target=None`, the deprecated function's own body is executed after a warning is issued. Warnings are initially suppressed for clean output but re-enabled to show the deprecation messages.

import warnings from deprecate import deprecated, void # Suppress DeprecationWarning for cleaner output in example, will re-enable later warnings.simplefilter('ignore', DeprecationWarning) # NEW/FUTURE API — renamed to be more explicit about what it computes def compute_sum(a: int = 0, b: int = 3) -> int: """Computes the sum of two numbers.""" return a + b # OLD API — 'addition' was the original name before the rename @deprecated(target=compute_sum, deprecated_in="1.0", remove_in="2.0", template_mgs="{name} is deprecated, use {target_path} instead.") def addition(a: int, b: int = 5) -> int: """Adds two numbers (deprecated).""" # The body of 'addition' is never executed because 'target' is specified. # The 'void' helper is used here to silence IDE warnings about 'a' and 'b' being unused. return void(a, b) # Deprecating a function with no direct target (its own body runs) @deprecated(target=None, deprecated_in="0.5", remove_in="0.8", template_mgs="Method {name} is deprecated and will be removed.") def old_method(value: str) -> str: """An old method that will be removed.""" return f"Processing: {value}" # Example usage: print("--- Using deprecated function with target ---") print(f"Result of addition(1, 2): {addition(1, 2)}") print(f"Result of addition(10): {addition(10)}") print("\n--- Using deprecated function with no target ---") print(f"Result of old_method('test'): {old_method('test')}") # To demonstrate the warning, re-enable DeprecationWarnings print("\n--- Enabling warnings to show deprecation output ---") warnings.simplefilter('default', DeprecationWarning) print(f"Result of addition(3, 4): {addition(3, 4)}") print(f"Result of old_method('another test'): {old_method('another test')}")
Debug
Known issues
gotchaWhen using `@deprecated` with a `target` function, the body of the deprecated function is never executed; all calls are automatically forwarded to the target. Do not put critical logic inside a deprecated function if a target is specified.
fix
Ensure all necessary logic resides within the `target` function. If the deprecated function's body *must* be executed, set `target=None` to only issue a warning without forwarding.
affects: All versions
gotchaConversely, if `target=None` is explicitly set in `@deprecated`, the deprecated function's own body *will* be executed after the warning is issued. This behavior is distinct from when a callable target is provided.
fix
Understand the behavior difference: `target=Callable` forwards calls and skips the deprecated body; `target=None` runs the deprecated body after warning. Choose based on whether the old implementation should still execute.
affects: All versions
gotcha`deprecated_instance` cannot intercept primitive protocol methods (e.g., numeric arithmetic on `float`, concatenation on `str`). This means direct operations on wrapped primitive constants will not trigger deprecation warnings.
fix
For primitive constants that need deprecation warnings, either wrap them in a custom object/dictionary or manually update all call sites to use the new API directly.
affects: All versions
gotchaWhen using `update_docstring=True` with the `@deprecated` decorator, consider setting the `docstring_style` parameter (e.g., `'sphinx'`, `'mkdocs'`, or `'auto'`) to ensure the deprecation notice is injected and formatted correctly for your specific documentation generator.
fix
Explicitly set `docstring_style` in the `@deprecated` decorator (e.g., `docstring_style='mkdocs'`) or use `docstring_style='auto'` to let `pydeprecate` attempt to detect the style from existing docstring content.
affects: 0.7.0 and later
Errors
Common errors & fixes
ImportError: cannot import name 'deprecated' from 'deprecate'
The `pydeprecate` library is installed as `pydeprecate`, but the main decorator is imported from the `deprecate` package, not `pydeprecate` directly.
fix
Ensure you import from the `deprecate` package: `from deprecate import deprecated`
TypeError: Cannot apply @deprecated to class 'MyClass'. For class-level deprecation use @deprecated_class() from deprecate.proxy.
The `@deprecated` decorator is designed for functions and methods, not entire classes. To deprecate a class, a different decorator or approach is required.
fix
Use the `@deprecated_class` decorator from `deprecate.proxy` for class-level deprecation: `from deprecate.proxy import deprecated_class`
Deprecation warnings not showing
By default, Python's `DeprecationWarning` (which `pydeprecate` emits) is often hidden or shown only once in many environments to prevent log spam. `pydeprecate` also defaults to showing warnings once per function.
fix
To ensure warnings are visible, you can use `warnings.simplefilter('always', DeprecationWarning)` in your code, run Python with the `-Wd` flag, or configure `pydeprecate`'s `num_warns` parameter (e.g., `@deprecated(num_warns=None)`) to show warnings unlimited times.
ERROR: <module>.<function> has invalid args: ['<arg_name>']
This error is reported by `pydeprecate`'s validation tools (e.g., `find_deprecation_wrappers` or `validate_deprecation_wrapper`) when `args_mapping` contains keys that do not correspond to actual arguments in the deprecated function's signature.
fix
Review the `args_mapping` dictionary in your `@deprecated` decorator to ensure all old argument names specified as keys exist in the function being deprecated.
Upgrade
Version history
0.11.0latest on PyPI · released Jul 17, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
pydeprecate — pip install pydeprecate · libregistry