diff --git a/wireup/annotation/__init__.py b/wireup/annotation/__init__.py index 9aa1a59..313cf6d 100644 --- a/wireup/annotation/__init__.py +++ b/wireup/annotation/__init__.py @@ -105,7 +105,7 @@ def wire(self) -> InjectableType | Callable[[], InjectableType]: return Inject(param=self.value) -__T = TypeVar("__T") +T = TypeVar("T") @dataclass @@ -127,26 +127,26 @@ def service( *, qualifier: Qualifier | None = None, lifetime: ServiceLifetime = ServiceLifetime.SINGLETON, -) -> Callable[[__T], __T]: +) -> Callable[[T], T]: pass @overload def service( - obj: __T, + obj: T, *, qualifier: Qualifier | None = None, lifetime: ServiceLifetime = ServiceLifetime.SINGLETON, -) -> __T: +) -> T: pass def service( - obj: __T | None = None, + obj: T | None = None, *, qualifier: Qualifier | None = None, lifetime: ServiceLifetime = ServiceLifetime.SINGLETON, -) -> __T | Callable[[__T], __T]: +) -> T | Callable[[T], T]: """Mark the decorated class as a service. If used on a function it will register it as a factory for the class @@ -155,7 +155,7 @@ def service( # Allow this to be used as a decorator factory or as a decorator directly. if obj is None: - def decorator(decorated_obj: __T) -> __T: + def decorator(decorated_obj: T) -> T: decorated_obj.__wireup_registration__ = ServiceDeclaration( # type: ignore[attr-defined] obj=decorated_obj, qualifier=qualifier, lifetime=lifetime ) @@ -168,7 +168,7 @@ def decorator(decorated_obj: __T) -> __T: return obj -def abstract(cls: type[__T]) -> type[__T]: +def abstract(cls: type[T]) -> type[T]: """Mark the decorated class as a service.""" cls.__wireup_registration__ = AbstractDeclaration() # type: ignore[attr-defined] diff --git a/wireup/ioc/dependency_container.py b/wireup/ioc/dependency_container.py index 21f4bfc..391329d 100644 --- a/wireup/ioc/dependency_container.py +++ b/wireup/ioc/dependency_container.py @@ -33,7 +33,7 @@ from wireup.ioc.initialization_context import InitializationContext from wireup.ioc.parameter import ParameterBag -__T = TypeVar("__T") +T = TypeVar("T") class DependencyContainer: @@ -70,7 +70,7 @@ def __init__(self, parameter_bag: ParameterBag) -> None: self.__active_overrides, self.__service_registry.is_type_with_qualifier_known ) - def get(self, klass: type[__T], qualifier: Qualifier | None = None) -> __T: + def get(self, klass: type[T], qualifier: Qualifier | None = None) -> T: """Get an instance of the requested type. Use this to locate services by their type but strongly prefer using injection instead. @@ -92,7 +92,7 @@ def get(self, klass: type[__T], qualifier: Qualifier | None = None) -> __T: return self.__create_concrete_type(klass, qualifier) - def abstract(self, klass: type[__T]) -> type[__T]: + def abstract(self, klass: type[T]) -> type[T]: """Register a type as an interface. This type cannot be initialized directly and one of the components implementing this will be injected instead. @@ -108,26 +108,26 @@ def register( *, qualifier: Qualifier | None = None, lifetime: ServiceLifetime = ServiceLifetime.SINGLETON, - ) -> Callable[[__T], __T]: + ) -> Callable[[T], T]: pass @overload def register( self, - obj: __T, + obj: T, *, qualifier: Qualifier | None = None, lifetime: ServiceLifetime = ServiceLifetime.SINGLETON, - ) -> __T: + ) -> T: pass def register( self, - obj: __T | None = None, + obj: T | None = None, *, qualifier: Qualifier | None = None, lifetime: ServiceLifetime = ServiceLifetime.SINGLETON, - ) -> __T | Callable[[__T], __T]: + ) -> T | Callable[[T], T]: """Register a dependency in the container. Dependency must be either a class or a factory function. * Use as a decorator without parameters @container.register on a factory function or class to register it. @@ -137,7 +137,7 @@ def register( # Allow register to be used either with or without arguments if obj is None: - def decorated(decorated_obj: __T) -> __T: + def decorated(decorated_obj: T) -> T: self.register(decorated_obj, qualifier=qualifier, lifetime=lifetime) return decorated_obj @@ -250,7 +250,7 @@ def __callable_get_params_to_inject(self, fn: AnyCallable) -> dict[str, Any]: return values_from_parameters - def __create_concrete_type(self, klass: type[__T], qualifier: Qualifier | None) -> __T: + def __create_concrete_type(self, klass: type[T], qualifier: Qualifier | None) -> T: """Create the real instances of dependencies. Additional dependencies they may have will be lazily created.""" obj_id = klass, qualifier @@ -266,8 +266,8 @@ def __create_concrete_type(self, klass: type[__T], qualifier: Qualifier | None) return instance # type: ignore[no-any-return] def __get_instance( - self, klass: type[__T], qualifier: Qualifier | None, annotation: InjectableType | None = None - ) -> __T | None: + self, klass: type[T], qualifier: Qualifier | None, annotation: InjectableType | None = None + ) -> T | None: if self.__service_registry.is_impl_known_from_factory(klass, qualifier): # Objects generated from factories do not have qualifiers return self.__create_concrete_type(klass, None) @@ -299,7 +299,7 @@ def __get_instance( return None - def __resolve_impl(self, klass: type[__T], qualifier: Qualifier | None) -> type[__T]: + def __resolve_impl(self, klass: type[T], qualifier: Qualifier | None) -> type[T]: impls = self.__service_registry.known_interfaces.get(klass, {}) if qualifier in impls: diff --git a/wireup/ioc/proxy.py b/wireup/ioc/proxy.py index 6736f4c..91dbe53 100644 --- a/wireup/ioc/proxy.py +++ b/wireup/ioc/proxy.py @@ -2,10 +2,10 @@ from typing import Any, Callable, Generic, TypeVar -__T = TypeVar("__T") +T = TypeVar("T") -class ContainerProxy(Generic[__T]): +class ContainerProxy(Generic[T]): """A proxy object used by the container to achieve lazy loading. Contains a reference to the final initialized object and proxies all requests to the instance. @@ -13,7 +13,7 @@ class ContainerProxy(Generic[__T]): __slots__ = ("__supplier", "__proxy_object") - def __init__(self, instance_supplier: Callable[[], __T]) -> None: + def __init__(self, instance_supplier: Callable[[], T]) -> None: """Initialize a ContainerProxy. :param instance_supplier: A callable which takes no arguments and returns the object. Will be called to