Skip to content

Commit

Permalink
Fix mypy issues
Browse files Browse the repository at this point in the history
With the latest version of it and Blinker.
  • Loading branch information
pgjones committed May 19, 2024
1 parent ba31554 commit 3508d9a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
32 changes: 20 additions & 12 deletions src/quart/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ async def handle_exception(self, error: Exception) -> ResponseTypes:
"""
exc_info = sys.exc_info()
await got_request_exception.send_async(
self, _sync_wrapper=self.ensure_async, exception=error
self, _sync_wrapper=self.ensure_async, exception=error # type: ignore
)
propagate = self.config["PROPAGATE_EXCEPTIONS"]

Expand Down Expand Up @@ -1069,7 +1069,7 @@ async def handle_websocket_exception(self, error: Exception) -> ResponseTypes |
"""
exc_info = sys.exc_info()
await got_websocket_exception.send_async(
self, _sync_wrapper=self.ensure_async, exception=error
self, _sync_wrapper=self.ensure_async, exception=error # type: ignore
)
propagate = self.config["PROPAGATE_EXCEPTIONS"]

Expand Down Expand Up @@ -1163,7 +1163,9 @@ async def do_teardown_request(
for function in reversed(self.teardown_request_funcs[name]):
await self.ensure_async(function)(exc)

await request_tearing_down.send_async(self, _sync_wrapper=self.ensure_async, exc=exc)
await request_tearing_down.send_async(
self, _sync_wrapper=self.ensure_async, exc=exc # type: ignore
)

async def do_teardown_websocket(
self, exc: BaseException | None, websocket_context: WebsocketContext | None = None
Expand All @@ -1181,13 +1183,17 @@ async def do_teardown_websocket(
for function in reversed(self.teardown_websocket_funcs[name]):
await self.ensure_async(function)(exc)

await websocket_tearing_down.send_async(self, _sync_wrapper=self.ensure_async, exc=exc)
await websocket_tearing_down.send_async(
self, _sync_wrapper=self.ensure_async, exc=exc # type: ignore
)

async def do_teardown_appcontext(self, exc: BaseException | None) -> None:
"""Teardown the app (context), calling the teardown functions."""
for function in self.teardown_appcontext_funcs:
await self.ensure_async(function)(exc)
await appcontext_tearing_down.send_async(self, _sync_wrapper=self.ensure_async, exc=exc)
await appcontext_tearing_down.send_async(
self, _sync_wrapper=self.ensure_async, exc=exc # type: ignore
)

def app_context(self) -> AppContext:
"""Create and return an app context.
Expand Down Expand Up @@ -1321,7 +1327,7 @@ async def _wrapper() -> None:

async def handle_background_exception(self, error: Exception) -> None:
await got_background_exception.send_async(
self, _sync_wrapper=self.ensure_async, exception=error
self, _sync_wrapper=self.ensure_async, exception=error # type: ignore
)

self.log_exception(sys.exc_info())
Expand Down Expand Up @@ -1424,7 +1430,7 @@ async def full_dispatch_request(
omits this argument.
"""
try:
await request_started.send_async(self, _sync_wrapper=self.ensure_async)
await request_started.send_async(self, _sync_wrapper=self.ensure_async) # type: ignore

result: ResponseReturnValue | HTTPException | None
result = await self.preprocess_request(request_context)
Expand All @@ -1444,7 +1450,9 @@ async def full_dispatch_websocket(
the Flask convention.
"""
try:
await websocket_started.send_async(self, _sync_wrapper=self.ensure_async)
await websocket_started.send_async(
self, _sync_wrapper=self.ensure_async # type: ignore
)

result: ResponseReturnValue | HTTPException | None
result = await self.preprocess_websocket(websocket_context)
Expand Down Expand Up @@ -1558,7 +1566,7 @@ async def finalize_request(
try:
response = await self.process_response(response, request_context)
await request_finished.send_async(
self, _sync_wrapper=self.ensure_async, response=response
self, _sync_wrapper=self.ensure_async, response=response # type: ignore
)
except Exception:
if not from_error_handler:
Expand Down Expand Up @@ -1586,7 +1594,7 @@ async def finalize_websocket(
try:
response = await self.postprocess_websocket(response, websocket_context)
await websocket_finished.send_async(
self, _sync_wrapper=self.ensure_async, response=response
self, _sync_wrapper=self.ensure_async, response=response # type: ignore
)
except Exception:
if not from_error_handler:
Expand Down Expand Up @@ -1693,7 +1701,7 @@ async def startup(self) -> None:
await gen.__anext__()
except Exception as error:
await got_serving_exception.send_async(
self, _sync_wrapper=self.ensure_async, exception=error
self, _sync_wrapper=self.ensure_async, exception=error # type: ignore
)
self.log_exception(sys.exc_info())
raise
Expand Down Expand Up @@ -1721,7 +1729,7 @@ async def shutdown(self) -> None:
raise RuntimeError("While serving generator didn't terminate")
except Exception as error:
await got_serving_exception.send_async(
self, _sync_wrapper=self.ensure_async, exception=error
self, _sync_wrapper=self.ensure_async, exception=error # type: ignore
)
self.log_exception(sys.exc_info())
raise
Expand Down
8 changes: 6 additions & 2 deletions src/quart/ctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ def copy(self) -> AppContext:

async def push(self) -> None:
self._cv_tokens.append(_cv_app.set(self))
await appcontext_pushed.send_async(self.app, _sync_wrapper=self.app.ensure_async)
await appcontext_pushed.send_async(
self.app, _sync_wrapper=self.app.ensure_async # type: ignore
)

async def pop(self, exc: BaseException | None = _sentinel) -> None: # type: ignore
try:
Expand All @@ -259,7 +261,9 @@ async def pop(self, exc: BaseException | None = _sentinel) -> None: # type: ign
if ctx is not self:
raise AssertionError(f"Popped wrong app context. ({ctx!r} instead of {self!r})")

await appcontext_popped.send_async(self.app, _sync_wrapper=self.app.ensure_async)
await appcontext_popped.send_async(
self.app, _sync_wrapper=self.app.ensure_async # type: ignore
)

async def __aenter__(self) -> AppContext:
await self.push()
Expand Down
2 changes: 1 addition & 1 deletion src/quart/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ async def save_session(
val = self.get_signing_serializer(app).dumps(dict(session))
response.set_cookie(
name,
val, # type: ignore
val,
expires=expires,
httponly=httponly,
domain=domain,
Expand Down
8 changes: 4 additions & 4 deletions src/quart/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ async def render_template_string(source: str, **context: Any) -> str:

async def _render(template: Template, context: dict, app: Quart) -> str:
await before_render_template.send_async(
app, _sync_wrapper=app.ensure_async, template=template, context=context
app, _sync_wrapper=app.ensure_async, template=template, context=context # type: ignore
)
rendered_template = await template.render_async(context)
await template_rendered.send_async(
app, _sync_wrapper=app.ensure_async, template=template, context=context
app, _sync_wrapper=app.ensure_async, template=template, context=context # type: ignore
)
return rendered_template

Expand Down Expand Up @@ -115,14 +115,14 @@ async def stream_template_string(source: str, **context: Any) -> AsyncIterator[s

async def _stream(app: Quart, template: Template, context: dict[str, Any]) -> AsyncIterator[str]:
await before_render_template.send_async(
app, _sync_wrapper=app.ensure_async, template=template, context=context
app, _sync_wrapper=app.ensure_async, template=template, context=context # type: ignore
)

async def generate() -> AsyncIterator[str]:
async for chunk in template.generate_async(context):
yield chunk
await template_rendered.send_async(
app, _sync_wrapper=app.ensure_async, template=template, context=context
app, _sync_wrapper=app.ensure_async, template=template, context=context # type: ignore
)

# If a request context is active, keep it while generating.
Expand Down

0 comments on commit 3508d9a

Please sign in to comment.