Skip to content

Commit

Permalink
overloading according to given type
Browse files Browse the repository at this point in the history
  • Loading branch information
dev0Guy committed Feb 8, 2025
1 parent 921db66 commit fd38152
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions nest/core/pynest_factory.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit fd38152

Please sign in to comment.