decohints

1.0.9 · active · verified Thu Apr 16

decohints is a Python library that provides a decorator to help IDEs like PyCharm correctly display the parameter hints for functions wrapped by other decorators. It addresses a common pain point in Python development by preserving the original function's signature for better developer experience and type checking. The current version is 1.0.9, and it maintains an active release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `decohints` to wrap your own decorator. When `my_simple_decorator` is decorated with `@decohints`, IDEs like PyCharm will correctly show the parameter hints of the `greet` function (`name: str, age: int`) instead of the generic `*args, **kwargs`.

from functools import wraps
from decohints import decohints

@decohints
def my_simple_decorator(msg: str = "Hello"):
    def _decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            print(f"Decorator received: {msg}")
            return func(*args, **kwargs)
        return wrapper
    return _decorator

@my_simple_decorator(msg="Decorating this!")
def greet(name: str, age: int) -> str:
    """A function that greets someone."""
    return f"Hi {name}, you are {age} years old."

result = greet("Alice", 30)
print(result)
# In PyCharm, typing `greet(` will now show `(name: str, age: int)` hints.

view raw JSON →