Skip to content

Commit

Permalink
Cleanup some typing (#3014)
Browse files Browse the repository at this point in the history
* Cleanup some typing

* Cleanup some typing

* Use actual dumps in test
  • Loading branch information
ahopkins authored Dec 16, 2024
1 parent da1c646 commit cce077c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions sanic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1672,14 1672,15 @@ def _loop_add_task(
name: Optional[str] = None,
register: bool = True,
) -> Task:
tsk: Task = task
if not isinstance(task, Future):
prepped = cls._prep_task(task, app, loop)
task = loop.create_task(prepped, name=name)
tsk = loop.create_task(prepped, name=name)

if name and register:
app._task_registry[name] = task
app._task_registry[name] = tsk

return task
return tsk

@staticmethod
async def dispatch_delayed_tasks(
Expand Down Expand Up @@ -1708,7 1709,7 @@ async def dispatch_delayed_tasks(
async def run_delayed_task(
app: Sanic,
loop: AbstractEventLoop,
task: Task[Any],
task: Union[Future[Any], Task[Any], Awaitable[Any]],
) -> None:
"""Executes a delayed task within the context of a given app and loop.
Expand Down
4 changes: 2 additions & 2 deletions sanic/mixins/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 248,7 @@ async def _static_request_handler(
self,
request: Request,
*,
file_or_directory: PathLike,
file_or_directory: str,
use_modified_since: bool,
use_content_range: bool,
stream_large_files: Union[bool, int],
Expand All @@ -258,7 258,7 @@ async def _static_request_handler(
):
not_found = FileNotFound(
"File not found",
path=file_or_directory,
path=Path(file_or_directory),
relative_url=__file_uri__,
)

Expand Down
5 changes: 3 additions & 2 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 19,7 @@
from sanic.constants import DEFAULT_HTTP_CONTENT_TYPE
from sanic.exceptions import ServerError
from sanic.request import RequestParameters
from sanic.response import html, json, text
from sanic.response import BaseHTTPResponse, html, json, text


def encode_basic_auth_credentials(username, password):
Expand Down Expand Up @@ -2253,8 2253,9 @@ async def delete(request, foo):
{"name": request.route.name, "body": str(request.body), "foo": foo}
)

dumps = BaseHTTPResponse._dumps
payload = {"test": "OK"}
data = str(json_dumps(payload).encode())
data = str(dumps(payload).encode())

_, response = app.test_client.put("/", json=payload)
assert response.status == 200
Expand Down

0 comments on commit cce077c

Please sign in to comment.