Improved cpl-discords service loading for commands and events

This commit is contained in:
2023-10-12 20:41:34 +02:00
parent f357e97ce5
commit 1dd48899d7
6 changed files with 27 additions and 47 deletions

View File

@@ -157,12 +157,12 @@ class ServiceProvider(ServiceProviderABC):
return implementation
def get_services(self, service_type: typing.Type[T], *args, **kwargs) -> list[Optional[T]]:
def get_services(self, service_type: T, *args, **kwargs) -> list[Optional[T]]:
implementations = []
if typing.get_origin(service_type) != list:
raise Exception(f"Invalid type {service_type}! Expected list of type")
if typing.get_origin(service_type) == list:
raise Exception(f"Invalid type {service_type}! Expected single type not list of type")
implementations.extend(self._get_services(typing.get_args(service_type)[0]))
implementations.extend(self._get_services(service_type))
return implementations

View File

@@ -76,7 +76,7 @@ class ServiceProviderABC(ABC):
pass
@abstractmethod
def get_services(self, service_type: Type[T], *args, **kwargs) -> list[Optional[T]]:
def get_services(self, service_type: T, *args, **kwargs) -> list[Optional[T]]:
r"""Returns instance of given type
Parameter