From fd38152eb40fa26494866d5d1c0c81d831e9a9ee Mon Sep 17 00:00:00 2001 From: dev0Guy <97923827+dev0Guy@users.noreply.github.com> Date: Sat, 8 Feb 2025 11:21:49 +0200 Subject: [PATCH] overloading according to given type --- nest/core/pynest_factory.py | 41 ++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/nest/core/pynest_factory.py b/nest/core/pynest_factory.py index 6f23fec..1271edf 100644 --- a/nest/core/pynest_factory.py +++ b/nest/core/pynest_factory.py @@ -1,26 +1,47 @@ -from abc import ABC, abstractmethod -from typing import Type, TypeVar +from typing import Type, TypeVar, overload, Union, Optional from nest.core.pynest_application import PyNestApp from nest.core.pynest_container import PyNestContainer from nest.engine.proto import App from nest.engine.fastapi import FastAPIApp + ModuleType = TypeVar("ModuleType") -# TODO: move default fastapi to here and add future implementation -class AbstractPyNestFactory(ABC): - @abstractmethod - def create(self, main_module: Type[ModuleType], **kwargs): - raise NotImplementedError +class PyNestFactory: + """Factory class for creating PyNest applications.""" + @staticmethod + @overload + def create( + main_module: Type[ModuleType], + app_cls: Type[FastAPIApp], + title: str = "", + description: str = "", + version: Optional[Union[str, int, float]] = None, + debug: bool = False, + ) -> PyNestApp: + """ + Create a PyNest application of FastAPIApp kind. + """ -class PyNestFactory(AbstractPyNestFactory): - """Factory class for creating PyNest applications.""" + @staticmethod + @overload + def create( + main_module: Type[ModuleType], + app_cls: Type[App], + ) -> PyNestApp: + """ + Create a PyNest application of FastAPIApp kind. + """ @staticmethod - def create(main_module: Type[ModuleType], app_cls: Type[App] = FastAPIApp, **kwargs) -> PyNestApp: + def create( + main_module: Type[ModuleType], + app_cls: Type[App] = FastAPIApp, + **kwargs + ) -> PyNestApp: """ Create a PyNest application with the specified main module class.