Fixed formatting
All checks were successful
Test before pr merge / test-lint (pull_request) Successful in 6s
Build on push / prepare (push) Successful in 9s
Build on push / core (push) Successful in 19s
Build on push / query (push) Successful in 19s
Build on push / dependency (push) Successful in 14s
Build on push / mail (push) Successful in 16s
Build on push / application (push) Successful in 19s
Build on push / database (push) Successful in 20s
Build on push / translation (push) Successful in 20s
Build on push / auth (push) Successful in 14s
Build on push / api (push) Successful in 15s

This commit is contained in:
2025-09-25 10:37:29 +02:00
parent e3e1703ff8
commit 0529269747
10 changed files with 23 additions and 16 deletions

View File

@@ -1,4 +1,3 @@
from .error import APIError, AlreadyExists, EndpointNotImplemented, Forbidden, NotFound, Unauthorized
from .logger import APILogger
from .settings import ApiSettings

View File

@@ -17,5 +17,4 @@ def _with_permissions(self: _ApplicationABC, *permissions: Type[Enum]) -> _Appli
return self
_ApplicationABC.extend(_ApplicationABC.with_permissions, _with_permissions)

View File

@@ -14,6 +14,7 @@ def dependency_error(src: str, package_name: str, e: ImportError = None) -> None
exit(1)
def module_dependency_error(src: str, module: str, e: ImportError = None) -> None:
Console.error(f"'{module}' is required to use feature: {src}. Please initialize it with `add_module({module})`.")
tb = traceback.format_exc()

View File

@@ -3,6 +3,7 @@ from typing import Type
TModule = Type["Module"]
class Module(ABC):
@staticmethod

View File

@@ -23,7 +23,9 @@ class ServiceProvider:
type_args = list(typing.get_args(service_type))
for descriptor in self._service_descriptors:
if typing.get_origin(service_type) is None and (descriptor.service_type == service_type or issubclass(descriptor.base_type, service_type)):
if typing.get_origin(service_type) is None and (
descriptor.service_type == service_type or issubclass(descriptor.base_type, service_type)
):
return descriptor
descriptor_base_type = typing.get_origin(descriptor.base_type) or descriptor.base_type
@@ -65,9 +67,7 @@ class ServiceProvider:
implementations.append(descriptor.implementation)
continue
implementation = self._build_service(
descriptor, *args, origin_service_type=service_type, **kwargs
)
implementation = self._build_service(descriptor, *args, origin_service_type=service_type, **kwargs)
if descriptor.lifetime in (ServiceLifetimeEnum.singleton, ServiceLifetimeEnum.scoped):
descriptor.implementation = implementation
@@ -81,7 +81,9 @@ class ServiceProvider:
parameter = param[1]
if parameter.name != "self" and parameter.annotation != Parameter.empty:
if typing.get_origin(parameter.annotation) == list:
params.append(self._get_services(typing.get_args(parameter.annotation)[0], service_type=origin_service_type))
params.append(
self._get_services(typing.get_args(parameter.annotation)[0], service_type=origin_service_type)
)
elif parameter.annotation == Source:
params.append(origin_service_type.__name__)
@@ -104,7 +106,9 @@ class ServiceProvider:
return params
def _build_service(self, descriptor: ServiceDescriptor, *args, origin_service_type: type = None, **kwargs) -> object:
def _build_service(
self, descriptor: ServiceDescriptor, *args, origin_service_type: type = None, **kwargs
) -> object:
if descriptor.implementation is not None:
service_type = type(descriptor.implementation)
else:
@@ -131,7 +135,11 @@ class ServiceProvider:
yield scoped_provider
def get_hosted_services(self) -> list[Optional[T]]:
hosted_services = [self.get_service(d.service_type) for d in self._service_descriptors if d.lifetime == ServiceLifetimeEnum.hosted]
hosted_services = [
self.get_service(d.service_type)
for d in self._service_descriptors
if d.lifetime == ServiceLifetimeEnum.hosted
]
return hosted_services
def get_service(self, service_type: Type[T], *args, **kwargs) -> Optional[T]:

View File

@@ -9,7 +9,6 @@ class MailModule(Module):
def dependencies() -> list[TModule]:
return []
@staticmethod
def register(collection: ServiceCollection):
collection.add_singleton(EMailClientABC, EMailClient)