{"id":480,"library":"deprecation","title":"Python Deprecation Utilities","description":"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]","status":"maintenance","version":"2.1.0","language":"python","source_language":"en","source_url":"https://github.com/briancurtin/deprecation","tags":["deprecation","decorator","warnings","maintenance","code quality"],"install":[{"cmd":"pip install deprecation","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"deprecated","correct":"from deprecation import deprecated"},{"symbol":"fail_if_not_removed","correct":"from deprecation import fail_if_not_removed"}],"quickstart":{"code":"import os\nimport warnings\nfrom deprecation import deprecated, fail_if_not_removed\n\n# Simulate library version for demonstration\n__version__ = \"1.5.0\"\n\n# Decorate a function as deprecated\n@deprecated(deprecated_in=\"1.0\", removed_in=\"2.0\", current_version=__version__,\n            details=\"This function is old, use new_api_function() instead.\")\ndef old_api_function():\n    \"\"\"An old function that is going to be removed.\"\"\"\n    return \"Result from old API\"\n\n# To see DeprecationWarnings, Python typically needs a special flag.\n# For quick testing, you can uncomment the line below:\n# os.environ['PYTHONWARNINGS'] = 'default'\n\nprint(f\"Calling deprecated function: {old_api_function()}\")\n\n# Example of fail_if_not_removed (typically used in a test suite)\n# This would cause an AssertionError if current_version >= removed_in\n# import unittest\n# class MyTests(unittest.TestCase):\n#     @fail_if_not_removed(removed_in=\"2.0\", current_version=__version__)\n#     def test_old_function_is_gone(self):\n#         # This test would fail if old_api_function still exists when version is 2.0 or higher\n#         pass","lang":"python","description":"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]"},"warnings":[{"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.","message":"Python'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]","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The `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]","severity":"breaking","affected_versions":"All versions"},{"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.","message":"There 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]","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-05-12T14:11:11.559Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Install the 'deprecation' library using pip: 'pip install deprecation'.","cause":"The 'deprecation' library is not installed in the Python environment.","error":"ModuleNotFoundError: No module named 'deprecation'"},{"fix":"Ensure the import statement is correct: 'from deprecation import deprecated'.","cause":"The 'deprecated' decorator is not correctly imported from the 'deprecation' library.","error":"ImportError: cannot import name 'deprecated' from 'deprecation'"},{"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\")'.","cause":"The 'deprecated' decorator is used without specifying the 'deprecated_in' argument.","error":"TypeError: deprecated() missing 1 required positional argument: 'deprecated_in'"},{"fix":"Ensure the import statement is correct: 'from deprecation import fail_if_not_removed'.","cause":"The 'fail_if_not_removed' decorator is not correctly imported from the 'deprecation' library.","error":"AttributeError: module 'deprecation' has no attribute 'fail_if_not_removed'"},{"fix":"Update the code to use the recommended alternative function as specified in the deprecation warning.","cause":"A function marked with the 'deprecated' decorator is being called.","error":"DeprecationWarning: Call to deprecated function 'foo'. (Use the bar function instead)"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":0.9,"disk_size":"18.4M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":1.2,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.3,"disk_size":"20.3M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.3,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":0.8,"disk_size":"12.2M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":0.8,"disk_size":"13M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":1.9,"disk_size":"11.8M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":1.8,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":0.8,"disk_size":"17.9M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}