-
-
Notifications
You must be signed in to change notification settings - Fork 143
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Currently we use a custom mypy plugin to fix typings of some decorators.
Plugin: https://github.com/dry-python/returns/blob/master/returns/contrib/mypy/_features/decorators.py
Progress: python/mypy#8645
PEP: https://www.python.org/dev/peps/pep-0612/
Source: https://github.com/python/cpython/blob/366dc3a1354078e38808b9c16276e97cca5b8aaf/Lib/typing.py#L730
Example:
from typing_extensions import ParamSpec
from typing import TypeVar, Callable
T = TypeVar('T')
P = ParamSpec('P')
def add_logging(f: Callable[P, T]) -> Callable[P, T]:
'''A type-safe decorator to add logging to a function.'''
def inner(*args: P.args, **kwargs: P.kwargs) -> T:
logging.info(f'{f.__name__} was called')
return f(*args, **kwargs)
return inner
@add_logging
def add_two(x: float, y: float) -> float:
'''Add two numbers together.'''
return x + yIt is not working right now, we need to wait until proper support is merged into mypy.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request