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)