Skip to content

Support ParamSpec #823

Closed
Closed
@sobolevn

Description

@sobolevn
Member

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 + y

It is not working right now, we need to wait until proper support is merged into mypy.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @sobolevn@thepabloaguilar

      Issue actions

        Support ParamSpec · Issue #823 · dry-python/returns