Skip to content

Commit

Permalink
Resolve Python 3.12 deprecation notice (#2959)
Browse files Browse the repository at this point in the history
* Resolve Python 3.12 deprecation notice

* Fix typing issue

* Fixed linting

* Update ASGI tests setting port explicitly

* Remove uvicorn limit

* Python 3.8/3.9 tests in ASGI module
  • Loading branch information
ahopkins authored Jun 22, 2024
1 parent f8e0a72 commit 33bc520
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sanic/request/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
)
else:
sanic_type = TypeVar("sanic_type")
ctx_type = TypeVar("ctx_type")
ctx_type = TypeVar("ctx_type", default=SimpleNamespace)


class Request(Generic[sanic_type, ctx_type]):
Expand Down
3 changes: 1 addition & 2 deletions sanic/touchup/schemes/ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ def visit_Expr(self, node: Expr) -> Any:

if isinstance(func, Attribute) and func.attr == "dispatch":
event = args[0]
if hasattr(event, "s"):
event_name = getattr(event, "value", event.s)
if event_name := getattr(event, "value", None):
if self._not_registered(event_name):
logger.debug(
f"Disabling event: {event_name}",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def str_to_bool(val: str) -> bool:
"mypy",
"docutils",
"pygments",
"uvicorn<0.15.0",
"uvicorn",
"slotscheck>=0.8.0,<1",
types_ujson,
]
Expand Down
18 changes: 15 additions & 3 deletions tests/test_asgi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import logging

from collections import deque, namedtuple
Expand All @@ -18,6 +19,8 @@
from sanic.server.websockets.connection import WebSocketConnection
from sanic.signals import RESERVED_NAMESPACES

from .conftest import get_port


try:
from unittest.mock import AsyncMock
Expand Down Expand Up @@ -53,6 +56,9 @@ def transport(message_stack, receive, send):

@pytest.fixture
def protocol(transport):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
transport.loop = loop
return transport.get_protocol()


Expand Down Expand Up @@ -91,7 +97,9 @@ class CustomServer(uvicorn.Server):
def install_signal_handlers(self):
pass

config = uvicorn.Config(app=app, loop="asyncio", limit_max_requests=0)
config = uvicorn.Config(
app=app, loop="asyncio", limit_max_requests=0, port=get_port()
)
server = CustomServer(config=config)

start_message = (
Expand Down Expand Up @@ -189,7 +197,9 @@ class CustomServer(uvicorn.Server):
def install_signal_handlers(self):
pass

config = uvicorn.Config(app=app, loop="asyncio", limit_max_requests=0)
config = uvicorn.Config(
app=app, loop="asyncio", limit_max_requests=0, port=get_port()
)
server = CustomServer(config=config)

start_message = (
Expand Down Expand Up @@ -261,7 +271,9 @@ class CustomServer(uvicorn.Server):
def install_signal_handlers(self):
pass

config = uvicorn.Config(app=app, loop="asyncio", limit_max_requests=0)
config = uvicorn.Config(
app=app, loop="asyncio", limit_max_requests=0, port=get_port()
)
server = CustomServer(config=config)

with pytest.warns(UserWarning) as records:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,10 @@ async def handler(request: Request):
"response has at least partially been sent."
)

error_msg2 = "Response stream was ended, no more response data is allowed to be sent."
error_msg2 = (
"Response stream was ended, no more response "
"data is allowed to be sent."
)

with caplog.at_level(ERROR):
_, response = app.test_client.get("/")
Expand Down

0 comments on commit 33bc520

Please sign in to comment.