{"library":"types-deprecated","title":"Typing Stubs for Deprecated","description":"This is a typeshed stub package that provides static type annotations for the 'Deprecated' Python library. It enables type checkers like Mypy and Pyright to analyze code using the `Deprecated` library, which offers a `@deprecated` decorator for marking functions, methods, or classes as deprecated and emitting runtime warnings. The `types-deprecated` package is part of the `typeshed` project and its release cadence is tied to typeshed updates, aiming for compatibility with `Deprecated~=1.3.1`.","status":"active","version":"1.3.1.20260402","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","type-checking","deprecated","decorator"],"install":[{"cmd":"pip install types-deprecated","lang":"bash","label":"For type checking"},{"cmd":"pip install Deprecated","lang":"bash","label":"For runtime functionality (required alongside stubs)"}],"dependencies":[{"reason":"This package provides typing stubs for the runtime library 'Deprecated'. The runtime library is required for actual execution.","package":"Deprecated","optional":false},{"reason":"A core dependency of the runtime 'Deprecated' library, used for its decorator implementation.","package":"wrapt","optional":false}],"imports":[{"symbol":"deprecated","correct":"from deprecated import deprecated"},{"note":"Used for marking specific function parameters as deprecated.","symbol":"deprecated_params","correct":"from deprecated.params import deprecated_params"},{"note":"Part of the public API but less commonly used directly than the decorator.","symbol":"DeprecatedMethod","correct":"from deprecated import DeprecatedMethod"},{"note":"Stubs packages like 'types-deprecated' provide type hints but do not contain runtime code. The actual decorator must be imported from the 'deprecated' library.","wrong":"from types_deprecated import deprecated"}],"quickstart":{"code":"import warnings\nfrom deprecated import deprecated\n\n# Enable DeprecationWarnings to be visible (they are often ignored by default)\nwarnings.simplefilter('always', DeprecationWarning)\n\n@deprecated(reason=\"Use new_function instead\")\ndef old_function(a: int, b: int) -> int:\n    \"\"\"This is an old function.\"\"\"\n    return a + b\n\n@deprecated(version='1.2.0', reason=\"Use NewClass instead\")\nclass OldClass:\n    def __init__(self, value: str):\n        self.value = value\n\n    def get_value(self) -> str:\n        return self.value\n\n\ndef new_function(x: int, y: int) -> int:\n    \"\"\"This is the new function.\"\"\"\n    return x * y\n\n\n# Using the deprecated function and class\nresult = old_function(5, 3)\nprint(f\"Result from old_function: {result}\")\n\nobj = OldClass(\"hello\")\nprint(f\"Value from OldClass: {obj.get_value()}\")\n\n\n# Expected usage of the new function\nnew_result = new_function(5, 3)\nprint(f\"Result from new_function: {new_result}\")\n\n# Example of using a deprecated parameter (requires deprecated.params)\nfrom deprecated.params import deprecated_params\n\n@deprecated_params('old_arg', reason='Use new_arg instead')\ndef example_function(new_arg: str, old_arg: str = 'default') -> None:\n    print(f\"Called with new_arg: {new_arg}, old_arg: {old_arg}\")\n\nexample_function(new_arg='modern value', old_arg='legacy value')\n\n# Restore default warning filter (optional)\nwarnings.simplefilter('default', DeprecationWarning)\n","lang":"python","description":"This quickstart demonstrates how to apply the `@deprecated` decorator to functions and classes from the `Deprecated` library. It also includes an example of using `@deprecated_params` for specific arguments. Crucially, it shows how to enable `DeprecationWarning` messages, which are often ignored by default in Python, so you can see the warnings generated by using deprecated code."},"warnings":[{"fix":"Ensure both `pip install Deprecated` and `pip install types-deprecated` are run.","message":"This `types-deprecated` package provides *only* type stubs. For the actual `@deprecated` decorator functionality at runtime, you must also install the `Deprecated` library (`pip install Deprecated`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"To view warnings, run your Python script with `python -W always your_script.py` or add `import warnings; warnings.simplefilter('always', DeprecationWarning)` at the beginning of your script during development/testing. For production, consider using a logging configuration to capture warnings.","message":"By default, `DeprecationWarning` messages are ignored in Python 2.7+ unless explicitly enabled (e.g., via `python -W always` or `warnings.simplefilter('always', DeprecationWarning)` in code). If you don't see warnings, they might be silently suppressed.","severity":"gotcha","affected_versions":"Python 2.7+"},{"fix":"Inform users in the deprecation message that the entire class is deprecated and they should migrate to an alternative class.","message":"When deprecating a class using `@deprecated`, the warning is typically emitted only during class instantiation (when `__new__` is called), not for every method call on an already-instantiated deprecated object.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Regularly update `types-deprecated` and review your code with a type checker for new type errors if you update the `Deprecated` runtime library to a new major version.","message":"The `types-deprecated` stubs aim to provide accurate annotations for `Deprecated~=1.3.1`. Future major versions of the runtime `Deprecated` library (e.g., 2.x) may introduce API changes that could break type checking, even if runtime code continues to function with older versions of the library.","severity":"breaking","affected_versions":"Future `Deprecated` 2.x+ versions"}],"env_vars":null,"last_verified":"2026-04-05T00:00:00.000Z","next_check":"2026-07-04T00:00:00.000Z"}