From 848c27b66980fbdfc619f658935de2c354ca6b1c Mon Sep 17 00:00:00 2001 From: Perchun Pak Date: Wed, 10 Jun 2026 21:22:36 +0200 Subject: [PATCH] Fix `autoparams` type annotation --- pyproject.toml | 2 ++ src/inject/__init__.py | 23 +++++++++-------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bc872a6..f793b7a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,6 +18,7 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", "Topic :: Software Development :: Libraries :: Python Modules", ] @@ -36,6 +37,7 @@ dev = [ "ruff", "mypy", "yamllint", + "typing-extensions", { include-group = "tests" }, ] diff --git a/src/inject/__init__.py b/src/inject/__init__.py index 851f310..d79f69e 100644 --- a/src/inject/__init__.py +++ b/src/inject/__init__.py @@ -102,6 +102,12 @@ def my_config(binder): else: from typing import _Union # noqa: ICN003, PLC2701 +if t.TYPE_CHECKING: + from typing_extensions import ParamSpec + + P = ParamSpec("P") +else: + P = object() logger = logging.getLogger("inject") @@ -639,26 +645,15 @@ def sign_up(name, email, cache, db): return _ParametersInjection(**args_to_classes) -# NOTE(pyctrl): only since 3.12 -# @t.overload -# def autoparams[T](fn: t.Callable[..., T]) -> t.Callable[..., T]: ... - - @t.overload -def autoparams(fn: t.Callable) -> t.Callable: ... - - -# NOTE(pyctrl): only since 3.12 -# @t.overload -# def autoparams[C: t.Callable](*selected: str) -> t.Callable[[C], C]: +def autoparams(fn: t.Callable[P, T]) -> t.Callable[P, T]: ... @t.overload -def autoparams(*selected: str) -> t.Callable: ... +def autoparams(*selected: str) -> t.Callable[[T], T]: ... -@t.no_type_check -def autoparams(*selected: str): +def autoparams(*selected: t.Callable[P, T] | str) -> t.Callable[..., T]: """ Return a decorator injecting args based on function type hints, only since 3.5.