Registry / testing / deprecation

deprecation

JSON →
library2.1.0pypypi✓ verified 10d ago

The `deprecation` library (version 2.1.0) provides decorators to manage automated deprecations in Python code, including updating docstrings and enabling test failures for removed code. It aims to automate the process of signaling deprecated features to users and ensuring timely removal of obsolete code. The library's last release was in April 2020, suggesting a maintenance or slower release cadence. [1, 7]

pip install deprecation
INSTALL
IMPORT
SIG · DEPRECATION
D
deprecation
testingpythonv2.1.0
Install
1.8s avg
Import
29ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.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.030s · 18.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.028s · 19MB
17MB installed
● package 17MB
Code
Verified usage

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

deprecated
from deprecation import deprecated
fail_if_not_removed
from deprecation import fail_if_not_removed

Demonstrates how to use the `@deprecated` decorator with versioning and how to call the decorated function. It also shows the typical use case for `fail_if_not_removed` in a testing context to ensure deprecated code is eventually removed. Note that `PYTHONWARNINGS` or a `-W` flag is often required to see `DeprecationWarning` messages at runtime. [1, 7]

import os import warnings from deprecation import deprecated, fail_if_not_removed # Simulate library version for demonstration __version__ = "1.5.0" # Decorate a function as deprecated @deprecated(deprecated_in="1.0", removed_in="2.0", current_version=__version__, details="This function is old, use new_api_function() instead.") def old_api_function(): """An old function that is going to be removed.""" return "Result from old API" # To see DeprecationWarnings, Python typically needs a special flag. # For quick testing, you can uncomment the line below: # os.environ['PYTHONWARNINGS'] = 'default' print(f"Calling deprecated function: {old_api_function()}") # Example of fail_if_not_removed (typically used in a test suite) # This would cause an AssertionError if current_version >= removed_in # import unittest # class MyTests(unittest.TestCase): # @fail_if_not_removed(removed_in="2.0", current_version=__version__) # def test_old_function_is_gone(self): # # This test would fail if old_api_function still exists when version is 2.0 or higher # pass
Debug
Known issues
gotchaPython's default behavior is to ignore `DeprecationWarning` messages. Users of this library (or any library emitting `DeprecationWarning`) will not see the warnings unless they explicitly configure Python (e.g., by running with `python -Wd` or setting the environment variable `PYTHONWARNINGS=default`). This can lead to silently using deprecated code. [1, 7]
fix
Ensure `PYTHONWARNINGS` environment variable is set to `default` or `always` in development and testing environments, or run Python with the `-Wd` or `-Wa` flag. For production, consider capturing warnings in logs.
affects: All versions
breakingThe `fail_if_not_removed` decorator is designed to raise an `AssertionError` if the `current_version` meets or exceeds the `removed_in` version specified. This is an intentional feature to enforce removal of obsolete code but will cause build or test failures in continuous integration pipelines if not properly managed as versions progress. [1, 7]
fix
Actively remove code that has passed its `removed_in` version to avoid test failures. Use `current_version` parameter accurately to reflect your project's version.
affects: All versions
gotchaThere is another popular and more actively maintained library named `Deprecated` (PyPI slug `Deprecated`, often imported as `from deprecated import deprecated`). Users might confuse these two distinct libraries due to similar names and functionality. Ensure you are importing from `deprecation` (lowercase PyPI slug) if you intend to use this specific library by Brian Curtin. [3, 9, 11]
fix
Double-check import statements to ensure `from deprecation import deprecated` for this library, and `from deprecated import deprecated` for the other. Consult the respective library's documentation for API differences.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'deprecation'
The 'deprecation' library is not installed in the Python environment.
fix
Install the 'deprecation' library using pip: 'pip install deprecation'.
ImportError: cannot import name 'deprecated' from 'deprecation'
The 'deprecated' decorator is not correctly imported from the 'deprecation' library.
fix
Ensure the import statement is correct: 'from deprecation import deprecated'.
TypeError: deprecated() missing 1 required positional argument: 'deprecated_in'
The 'deprecated' decorator is used without specifying the 'deprecated_in' argument.
fix
Provide the 'deprecated_in' argument when using the decorator: '@deprecated(deprecated_in="1.0", removed_in="2.0", current_version=__version__, details="Use the bar function instead")'.
AttributeError: module 'deprecation' has no attribute 'fail_if_not_removed'
The 'fail_if_not_removed' decorator is not correctly imported from the 'deprecation' library.
fix
Ensure the import statement is correct: 'from deprecation import fail_if_not_removed'.
DeprecationWarning: Call to deprecated function 'foo'. (Use the bar function instead)
A function marked with the 'deprecated' decorator is being called.
fix
Update the code to use the recommended alternative function as specified in the deprecation warning.
Upgrade
Version history
2.1.0latest on PyPI · released Apr 20, 2020
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
18
Amazon
1
Resources
deprecation — pip install deprecation · libregistry