This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author GBeauregard
Recipients AlexWaygood, GBeauregard, JelleZijlstra, gvanrossum, kj
Date 2022-02-04.22:19:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1644013165.99.0.0164231326825.issue46643@roundup.psfhosted.org>
In-reply-to
Content
Consider the following.
```
import logging
from typing import Annotated, Callable, ParamSpec, TypeVar

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: Annotated[P.args, "meta"], **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
```
This raises an error at runtime because P.args/P.kwargs cannot pass the typing._type_check called by Annotated because they are not callable(). This prevents being able to use Annotated on these type annotations.

This can be fixed by adding __call__ methods that raise to typing.ParamSpecArgs and typing.ParamSpecKwargs to match other typeforms.

I can write this patch given agreement
History
Date User Action Args
2022-02-04 22:19:26GBeauregardsetrecipients: + GBeauregard, gvanrossum, JelleZijlstra, kj, AlexWaygood
2022-02-04 22:19:25GBeauregardsetmessageid: <1644013165.99.0.0164231326825.issue46643@roundup.psfhosted.org>
2022-02-04 22:19:25GBeauregardlinkissue46643 messages
2022-02-04 22:19:25GBeauregardcreate