Skip to content

Commit 448ae74

Browse files
authored
Merge pull request #180 from python-ellar/starlette_0_37_support
Starlette 0.37.1 support
2 parents 7091d1f + a5a8616 commit 448ae74

File tree

11 files changed

+21
-22
lines changed

11 files changed

+21
-22
lines changed

ellar/app/factory.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from ellar.core.modules import ModuleRefBase
1111
from ellar.di import EllarInjector, ProviderConfig
1212
from ellar.reflect import reflect
13-
from ellar.threading import run_as_async
1413
from ellar.utils import get_unique_type
1514
from starlette.routing import BaseRoute, Host, Mount
1615

@@ -119,8 +118,7 @@ def _build_modules(
119118
return routes
120119

121120
@classmethod
122-
@run_as_async
123-
async def _create_app(
121+
def _create_app(
124122
cls,
125123
module: t.Type[t.Union[ModuleBase, t.Any]],
126124
global_guards: t.Optional[
@@ -206,7 +204,7 @@ def create_app(
206204
)
207205
app_factory_module = get_unique_type()
208206
module(app_factory_module)
209-
return cls._create_app( # type:ignore[no-any-return]
207+
return cls._create_app(
210208
module=app_factory_module,
211209
config_module=config_module,
212210
global_guards=global_guards,
@@ -221,6 +219,6 @@ def create_from_app_module(
221219
] = None,
222220
config_module: t.Union[str, t.Dict, None] = None,
223221
) -> App:
224-
return cls._create_app( # type:ignore[no-any-return]
222+
return cls._create_app(
225223
module, config_module=config_module, global_guards=global_guards
226224
)

ellar/common/exceptions/callable_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async def catch(
6767
args = tuple(list(self.func_args) + [ctx, exc])
6868
if self.is_async:
6969
return await self.callable_exception_handler(*args) # type:ignore[misc]
70-
return await run_in_threadpool(self.callable_exception_handler, *args)
70+
return await run_in_threadpool(self.callable_exception_handler, *args) # type:ignore[arg-type]
7171

7272
def __eq__(self, other: t.Any) -> bool:
7373
if isinstance(other, CallableExceptionHandler):

ellar/core/middleware/middleware.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010

1111

1212
class EllarMiddleware(Middleware, IEllarMiddleware):
13+
@t.no_type_check
1314
def __init__(self, cls: t.Type[T], **options: t.Any) -> None:
1415
super().__init__(cls, **options)
1516
injectable()(self.cls)
16-
self.options = build_init_kwargs(self.cls, self.options)
17+
self.kwargs = build_init_kwargs(self.cls, self.kwargs)
1718

18-
def __call__(self, app: ASGIApp, injector: EllarInjector) -> T: # type:ignore[type-var]
19-
self.options.update(app=app)
20-
return injector.create_object(self.cls, additional_kwargs=self.options)
19+
@t.no_type_check
20+
def __call__(self, app: ASGIApp, injector: EllarInjector) -> T:
21+
self.kwargs.update(app=app)
22+
return injector.create_object(self.cls, additional_kwargs=self.kwargs)

ellar/core/routing/file_mount.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import os.path
22
import typing as t
33

4-
from ellar.common.staticfiles import StaticFiles
54
from ellar.common.types import ASGIApp
5+
from ellar.core.staticfiles import StaticFiles
66
from ellar.utils.importer import get_main_directory_by_stack
77
from starlette.middleware import Middleware
88
from starlette.routing import BaseRoute, Mount
@@ -37,8 +37,8 @@ def __init__(
3737

3838
def _combine_app_with_middleware(self, app: ASGIApp) -> ASGIApp:
3939
if self._middleware is not None:
40-
for cls, options in reversed(self._middleware):
41-
app = cls(app=app, **options)
40+
for cls, _, kwargs in reversed(self._middleware):
41+
app = cls(app=app, **kwargs)
4242
return app
4343

4444
@property

ellar/testing/module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def get_test_client(
6868
base_url: str = "http://testserver",
6969
raise_server_exceptions: bool = True,
7070
root_path: str = "",
71-
backend: str = "asyncio",
71+
backend: t.Literal["asyncio", "trio"] = "asyncio",
7272
backend_options: t.Optional[t.Dict[str, t.Any]] = None,
7373
**kwargs: t.Any,
7474
) -> TestClient:

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ classifiers = [
4141

4242
dependencies = [
4343
"injector == 0.21.0",
44-
"starlette == 0.31.1",
44+
"starlette == 0.37.1",
4545
"pydantic >=2.5.1,<3.0.0",
4646
"jinja2",
4747
# CLI
@@ -81,7 +81,7 @@ test = [
8181
"types-redis ==4.6.0.20240106",
8282
"types-dataclasses ==0.6.6",
8383
"python-socketio",
84-
"uvicorn[standard] == 0.25.0",
84+
"uvicorn[standard] == 0.27.1",
8585
"aiohttp == 3.9.3",
8686
"argon2-cffi == 23.1.0"
8787
]

tests/test_auth/test_session/test_session_client_strategy.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ def test_session_cookie_sub_path():
125125
)
126126
test_module.override_provider(SessionStrategy, use_class=SessionClientStrategy)
127127

128-
client_second_app = test_module.get_test_client(
129-
base_url="http://testserver/second_app"
130-
)
128+
client_second_app = test_module.get_test_client(root_path="/second_app")
131129
client = test_module.get_test_client(base_url="http://testserver/")
132130

133131
response = client_second_app.post("/second_app/", json={"some": "data"})

tests/test_modules/test_module_ref.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ async def middleware_func(cls, context, call_next):
176176
config_middleware = config[MIDDLEWARE_HANDLERS_KEY]
177177

178178
assert isinstance(config_middleware, list)
179-
assert "middleware_func" == get_name(config_middleware[0].options["dispatch"])
179+
assert "middleware_func" == get_name(config_middleware[0].kwargs["dispatch"])
180180

181181

182182
def test_module_template_ref_get_all_routers():

tests/test_routing/test_route_endpoint_params.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ def get_requests_case_1(
4141

4242
@router.get("/others")
4343
def get_requests_case_2(
44+
request: StarletteRequest,
4445
session: Inject[dict, Inject.Key("Session")],
4546
host: Inject[str, Inject.Key("Host")],
4647
config: Inject[Config],
4748
):
4849
assert isinstance(config, Config) # True
49-
assert host == "testclient"
50+
assert host is None # Starlette TestClient client info is None
5051
assert isinstance(session, dict) and len(session) == 0
5152
return True
5253

0 commit comments

Comments
 (0)