From 2ec8fc22b36040c0c78d4ecba3ca208697349837 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 11 Apr 2023 12:50:05 +0200 Subject: [PATCH 1/3] Improved generic type hints --- src/cpl_core/configuration/configuration.py | 2 +- src/cpl_core/configuration/configuration_abc.py | 2 +- src/cpl_core/dependency_injection/service_collection.py | 6 +++--- src/cpl_core/dependency_injection/service_collection_abc.py | 6 +++--- src/cpl_core/dependency_injection/service_provider.py | 4 ++-- src/cpl_core/dependency_injection/service_provider_abc.py | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/cpl_core/configuration/configuration.py b/src/cpl_core/configuration/configuration.py index a8372cac..aa3eab53 100644 --- a/src/cpl_core/configuration/configuration.py +++ b/src/cpl_core/configuration/configuration.py @@ -294,7 +294,7 @@ class Configuration(ConfigurationABC): self.add_configuration(sub, configuration) - def add_configuration(self, key_type: T, value: any): + def add_configuration(self, key_type: Type[T], value: any): self._config[key_type] = value def create_console_argument( diff --git a/src/cpl_core/configuration/configuration_abc.py b/src/cpl_core/configuration/configuration_abc.py index 815fa361..96ae8401 100644 --- a/src/cpl_core/configuration/configuration_abc.py +++ b/src/cpl_core/configuration/configuration_abc.py @@ -77,7 +77,7 @@ class ConfigurationABC(ABC): pass @abstractmethod - def add_configuration(self, key_type: T, value: any): + def add_configuration(self, key_type: Type[T], value: any): r"""Add configuration object Parameter: diff --git a/src/cpl_core/dependency_injection/service_collection.py b/src/cpl_core/dependency_injection/service_collection.py index acdf099f..4f6be8c7 100644 --- a/src/cpl_core/dependency_injection/service_collection.py +++ b/src/cpl_core/dependency_injection/service_collection.py @@ -61,15 +61,15 @@ class ServiceCollection(ServiceCollectionABC): self.add_transient(PipeABC, pipe) return self - def add_singleton(self, service_type: T, service: T = None): + def add_singleton(self, service_type: Type[T], service: T = None): self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.singleton, service) return self - def add_scoped(self, service_type: T, service: Callable = None): + def add_scoped(self, service_type: Type[T], service: Callable = None): self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.scoped, service) return self - def add_transient(self, service_type: T, service: T = None): + def add_transient(self, service_type: Type[T], service: T = None): self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.transient, service) return self diff --git a/src/cpl_core/dependency_injection/service_collection_abc.py b/src/cpl_core/dependency_injection/service_collection_abc.py index 8da9a519..62c1b5a8 100644 --- a/src/cpl_core/dependency_injection/service_collection_abc.py +++ b/src/cpl_core/dependency_injection/service_collection_abc.py @@ -46,7 +46,7 @@ class ServiceCollectionABC(ABC): pass @abstractmethod - def add_transient(self, service_type: T, service: T = None) -> "ServiceCollectionABC": + def add_transient(self, service_type: Type[T], service: T = None) -> "ServiceCollectionABC": r"""Adds a service with transient lifetime Parameter: @@ -61,7 +61,7 @@ class ServiceCollectionABC(ABC): pass @abstractmethod - def add_scoped(self, service_type: T, service: T = None) -> "ServiceCollectionABC": + def add_scoped(self, service_type: Type[T], service: T = None) -> "ServiceCollectionABC": r"""Adds a service with scoped lifetime Parameter: @@ -76,7 +76,7 @@ class ServiceCollectionABC(ABC): pass @abstractmethod - def add_singleton(self, service_type: T, service: T = None) -> "ServiceCollectionABC": + def add_singleton(self, service_type: Type[T], service: T = None) -> "ServiceCollectionABC": r"""Adds a service with singleton lifetime Parameter: diff --git a/src/cpl_core/dependency_injection/service_provider.py b/src/cpl_core/dependency_injection/service_provider.py index 8084b936..ac1225db 100644 --- a/src/cpl_core/dependency_injection/service_provider.py +++ b/src/cpl_core/dependency_injection/service_provider.py @@ -138,7 +138,7 @@ class ServiceProvider(ServiceProviderABC): sb = ScopeBuilder(ServiceProvider(descriptors, self._configuration, self._database_context)) return sb.build() - def get_service(self, service_type: T, *args, **kwargs) -> Optional[T]: + def get_service(self, service_type: typing.Type[T], *args, **kwargs) -> Optional[T]: result = self._find_service(service_type) if result is None: @@ -157,7 +157,7 @@ class ServiceProvider(ServiceProviderABC): return implementation - def get_services(self, service_type: T, *args, **kwargs) -> list[Optional[T]]: + def get_services(self, service_type: typing.Type[T], *args, **kwargs) -> list[Optional[T]]: implementations = [] if typing.get_origin(service_type) != list: diff --git a/src/cpl_core/dependency_injection/service_provider_abc.py b/src/cpl_core/dependency_injection/service_provider_abc.py index 7d51e751..dd195571 100644 --- a/src/cpl_core/dependency_injection/service_provider_abc.py +++ b/src/cpl_core/dependency_injection/service_provider_abc.py @@ -1,7 +1,7 @@ import functools from abc import abstractmethod, ABC from inspect import Signature, signature -from typing import Type, Optional +from typing import Optional, Type from cpl_core.dependency_injection.scope_abc import ScopeABC from cpl_core.type import T @@ -61,7 +61,7 @@ class ServiceProviderABC(ABC): pass @abstractmethod - def get_service(self, instance_type: T, *args, **kwargs) -> Optional[T]: + def get_service(self, instance_type: Type[T], *args, **kwargs) -> Optional[T]: r"""Returns instance of given type Parameter @@ -76,7 +76,7 @@ class ServiceProviderABC(ABC): pass @abstractmethod - def get_services(self, service_type: T, *args, **kwargs) -> list[Optional[T]]: + def get_services(self, service_type: Type[T], *args, **kwargs) -> list[Optional[T]]: r"""Returns instance of given type Parameter From 558dfb8cedb0c5a46848ddd19f506cec75ce4bf7 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 11 Apr 2023 12:51:49 +0200 Subject: [PATCH 2/3] Deactivated test output --- unittests/unittests_cli/threads/start_test_thread.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/unittests_cli/threads/start_test_thread.py b/unittests/unittests_cli/threads/start_test_thread.py index 833fb5b3..7eb2a3a8 100644 --- a/unittests/unittests_cli/threads/start_test_thread.py +++ b/unittests/unittests_cli/threads/start_test_thread.py @@ -9,4 +9,4 @@ class StartTestThread(threading.Thread): self._is_dev = is_dev def run(self): - CLICommands.start(is_dev=self._is_dev, output=True) + CLICommands.start(is_dev=self._is_dev) From cf5ae89884734e4b3f71ab93449d040f4dbcc373 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 11 Apr 2023 14:26:17 +0200 Subject: [PATCH 3/3] Fixed start test --- unittests/unittests_cli/threads/start_test_thread.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/unittests_cli/threads/start_test_thread.py b/unittests/unittests_cli/threads/start_test_thread.py index 7eb2a3a8..833fb5b3 100644 --- a/unittests/unittests_cli/threads/start_test_thread.py +++ b/unittests/unittests_cli/threads/start_test_thread.py @@ -9,4 +9,4 @@ class StartTestThread(threading.Thread): self._is_dev = is_dev def run(self): - CLICommands.start(is_dev=self._is_dev) + CLICommands.start(is_dev=self._is_dev, output=True)