Registry / type-stubs / types-decorator

types-decorator

JSON →
library5.2.0.20260712pypypi✓ verified 24d ago

types-decorator provides high-quality static type annotations (stubs) for the popular `decorator` Python library. It enables type checkers like MyPy and Pyright to analyze code using `decorator` for type correctness, enhancing maintainability and catching potential errors early. Maintained by the `typeshed` project, these stubs are automatically released to PyPI regularly, often daily, to reflect updates in the upstream library. The current version is 5.2.0.20260408.

pip install types-decorator
INSTALL
IMPORT
SIG · TYPES-DECORATOR
T
types-decorator
type-stubspythonv5.2.0.20260712
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.2.0.20260712 · 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.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

decorator
from decorator-stubs import decorator
from decorator-stubs import decorator

This quickstart demonstrates how to use the `decorator` library (for which `types-decorator` provides stubs) to create a custom decorator that warns if a function takes too long to execute. It showcases both a simple decorator application and a decorator factory with arguments, while automatically preserving the decorated function's signature and metadata.

import time import logging from decorator import decorator logging.basicConfig(level=logging.INFO) @decorator def warn_slow(func, timelimit=60, *args, **kw): """A decorator factory that logs if a function call exceeds a timelimit.""" t0 = time.time() result = func(*args, **kw) dt = time.time() - t0 if dt > timelimit: logging.warning('%s took %.2f seconds (exceeded %d s)', func.__name__, dt, timelimit) else: logging.info('%s took %.2f seconds', func.__name__, dt) return result @warn_slow def process_data(duration: float): """Simulates a data processing operation.""" time.sleep(duration) return f"Processed data in {duration} seconds" @warn_slow(timelimit=1) # Override default timelimit def analyze_report(duration: float): """Simulates a report analysis with a custom timelimit.""" time.sleep(duration) return f"Analyzed report in {duration} seconds (custom timelimit)" # Example usage: print(process_data(0.5)) print(process_data(2.0)) print(analyze_report(0.8)) print(analyze_report(1.5))
Debug
Known issues
breakingTypeshed stub packages, including `types-decorator`, can sometimes introduce changes that might cause your code to fail type checking, even if the runtime `decorator` library itself hasn't changed. This is due to updates in the stub definitions for improved accuracy or to align with new Python typing features.
fix
It is highly recommended to pin the version of `types-decorator` to match the major.minor version of the `decorator` library you are using (e.g., `types-decorator==5.2.*` for `decorator==5.2.*`). This ensures the stubs are compatible with your runtime library. Regularly update and re-run your type checker to catch any new issues.
affects: All versions of types-decorator
gotchaWhen creating custom decorators manually (without using `decorator.decorator`), a common pitfall is that the decorated function loses its original metadata (like `__name__`, `__doc__`, `__module__`) and signature. This can hinder debugging, introspection, and tools that rely on function signatures.
fix
The `decorator` library's `decorator` function automatically handles preservation of metadata and signature. If writing a custom decorator without this library, always use `@functools.wraps(func)` on your inner wrapper function. For example: `import functools; def my_decorator(func): @functools.wraps(func) def wrapper(*args, **kwargs): return func(*args, **kwargs) return wrapper`
affects: All Python versions when writing manual decorators
gotchaWhen applying multiple decorators to a single function, their order of application matters. Decorators are applied in reverse order of their appearance in the code, meaning the decorator closest to the function definition is applied first, and the topmost decorator is applied last.
fix
Carefully consider the interaction between decorators and test functions with stacked decorators thoroughly. If the behavior is unexpected, try reordering the decorators.
affects: All Python versions
Upgrade
Version history
5.2.0.20260712latest on PyPI · released Jul 12, 2026
Audit
Dependencies
decoratorrequiredThis package provides typing stubs for the 'decorator' library, which is a runtime dependency for functionality.
Agent activity
29 hits · last 30 days
node
26
OpenAI (training)
1
Resources
types-decorator — pip install types-decorator · libregistry