Skip to content

Commit cce077c

Browse files
authored
Cleanup some typing (#3014)
* Cleanup some typing * Cleanup some typing * Use actual dumps in test
1 parent da1c646 commit cce077c

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

sanic/app.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1672,14 +1672,15 @@ def _loop_add_task(
16721672
name: Optional[str] = None,
16731673
register: bool = True,
16741674
) -> Task:
1675+
tsk: Task = task
16751676
if not isinstance(task, Future):
16761677
prepped = cls._prep_task(task, app, loop)
1677-
task = loop.create_task(prepped, name=name)
1678+
tsk = loop.create_task(prepped, name=name)
16781679

16791680
if name and register:
1680-
app._task_registry[name] = task
1681+
app._task_registry[name] = tsk
16811682

1682-
return task
1683+
return tsk
16831684

16841685
@staticmethod
16851686
async def dispatch_delayed_tasks(
@@ -1708,7 +1709,7 @@ async def dispatch_delayed_tasks(
17081709
async def run_delayed_task(
17091710
app: Sanic,
17101711
loop: AbstractEventLoop,
1711-
task: Task[Any],
1712+
task: Union[Future[Any], Task[Any], Awaitable[Any]],
17121713
) -> None:
17131714
"""Executes a delayed task within the context of a given app and loop.
17141715

sanic/mixins/static.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ async def _static_request_handler(
248248
self,
249249
request: Request,
250250
*,
251-
file_or_directory: PathLike,
251+
file_or_directory: str,
252252
use_modified_since: bool,
253253
use_content_range: bool,
254254
stream_large_files: Union[bool, int],
@@ -258,7 +258,7 @@ async def _static_request_handler(
258258
):
259259
not_found = FileNotFound(
260260
"File not found",
261-
path=file_or_directory,
261+
path=Path(file_or_directory),
262262
relative_url=__file_uri__,
263263
)
264264

tests/test_requests.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from sanic.constants import DEFAULT_HTTP_CONTENT_TYPE
2020
from sanic.exceptions import ServerError
2121
from sanic.request import RequestParameters
22-
from sanic.response import html, json, text
22+
from sanic.response import BaseHTTPResponse, html, json, text
2323

2424

2525
def encode_basic_auth_credentials(username, password):
@@ -2253,8 +2253,9 @@ async def delete(request, foo):
22532253
{"name": request.route.name, "body": str(request.body), "foo": foo}
22542254
)
22552255

2256+
dumps = BaseHTTPResponse._dumps
22562257
payload = {"test": "OK"}
2257-
data = str(json_dumps(payload).encode())
2258+
data = str(dumps(payload).encode())
22582259

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

0 commit comments

Comments
 (0)