11import os
22from pathlib import Path
3- from typing import TYPE_CHECKING , Any , Callable , Generic , List , Optional , Type , TypeVar
3+ from typing import TYPE_CHECKING , Optional
4+ from typing import Type , Callable , Any , List , TypeVar , Generic
45
56from fastapi_startkit .providers .app_provider import AppProvider
6-
77from .config import AppConfig
88from .configuration .providers import ConfigurationProvider
99from .container import Container
1010from .environment .environment import LoadEnvironment
1111
1212if TYPE_CHECKING :
13- from fastapi import APIRouter , FastAPI
13+ from fastapi import FastAPI , APIRouter
1414 from starlette .middleware .base import BaseHTTPMiddleware
1515
1616from fastapi_startkit .exceptions import ExceptionHandler
@@ -64,7 +64,9 @@ def __init__(
6464 self .load_providers ()
6565
6666 def configure_exception_handler (self ):
67- self .exception_manager : ExceptionHandler = self ._exception_handler_class (application = self )
67+ self .exception_manager : ExceptionHandler = self ._exception_handler_class (
68+ application = self
69+ )
6870 self .exception_manager .register ()
6971 self .exception_manager .install ()
7072 self .bind ("exception_manager" , self .exception_manager )
@@ -75,8 +77,6 @@ def register_providers(self):
7577 config = {}
7678 if isinstance (provider_data , tuple ):
7779 provider_class , config = provider_data
78- if callable (config ):
79- config = config ()
8080 else :
8181 provider_class = provider_data
8282
@@ -129,8 +129,9 @@ def include_router(self, router: "APIRouter", **kwargs):
129129 return self
130130
131131 # Add middleware
132- def add_middleware (self , middleware_class : type [Any ], * args : Any , ** kwargs : Any ) -> None :
133- self ._fastapi .add_middleware (middleware_class , * args , ** kwargs )
132+ def add_middleware (self , middleware_class : Type ["BaseHTTPMiddleware" ], ** options ):
133+ self ._fastapi .add_middleware (middleware_class , ** options )
134+ return self
134135
135136 # Add event handlers (startup/shutdown)
136137 def add_event_handler (self , event_type : str , func : Callable [..., Any ]):
@@ -143,7 +144,9 @@ def mount(self, path: str, app_instance: "FastAPI", **kwargs):
143144 return self
144145
145146 # Add custom exception handlers
146- def add_exception_handler (self , exc_class_or_status_code : Any , handler : Callable [..., Any ]):
147+ def add_exception_handler (
148+ self , exc_class_or_status_code : Any , handler : Callable [..., Any ]
149+ ):
147150 self ._fastapi .add_exception_handler (exc_class_or_status_code , handler )
148151 return self
149152
@@ -153,7 +156,9 @@ def fastapi(self) -> "FastAPI":
153156 try :
154157 from fastapi import FastAPI
155158 except ImportError :
156- raise RuntimeError ("FastAPI is not installed. Install it with: pip install fastapi" )
159+ raise RuntimeError (
160+ "FastAPI is not installed. Install it with: pip install fastapi"
161+ )
157162 self ._fastapi = FastAPI ()
158163 # Making the type hint work
159164 assert self ._fastapi is not None
0 commit comments