Skip to content

Commit

Permalink
__T -> T
Browse files Browse the repository at this point in the history
  • Loading branch information
maldoinc committed Jul 31, 2024
1 parent 0994031 commit 5d14568
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
16 changes: 8 additions & 8 deletions wireup/annotation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def wire(self) -> InjectableType | Callable[[], InjectableType]:
return Inject(param=self.value)


__T = TypeVar("__T")
T = TypeVar("T")


@dataclass
Expand All @@ -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
Expand All @@ -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
)
Expand All @@ -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]

Expand Down
26 changes: 13 additions & 13 deletions wireup/ioc/dependency_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions wireup/ioc/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

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.
"""

__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
Expand Down

0 comments on commit 5d14568

Please sign in to comment.