From 2caf50253d992ca6d3a6f162d3a95e501b08fbe5 Mon Sep 17 00:00:00 2001 From: chesnok Date: Thu, 21 Nov 2024 19:58:36 +0300 Subject: [PATCH] add annotations for resolve container --- punq/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/punq/__init__.py b/punq/__init__.py index 8257f2b..8cee804 100644 --- a/punq/__init__.py +++ b/punq/__init__.py @@ -21,10 +21,12 @@ from collections import defaultdict from enum import Enum from importlib.metadata import PackageNotFoundError, version -from typing import Any, Callable, NamedTuple, get_type_hints +from typing import Any, Callable, NamedTuple, get_type_hints, TypeVar, Type from ._compat import ensure_forward_ref, is_generic_list +T = TypeVar('T') + with contextlib.suppress(PackageNotFoundError): __version__ = version(__name__) @@ -508,7 +510,7 @@ def _resolve_impl(self, service_key, kwargs, context, default=None): return self._build_impl(registration, kwargs, context) - def resolve(self, service_key, **kwargs): + def resolve(self, service_key: Type[T], **kwargs) -> T: """Build and return an instance of a registered service.""" context = self.registrations.build_context(service_key)