Skip to content

Commit 30ec9aa

Browse files
committed
Remove invalid uses of AnyStr
1 parent 5817e98 commit 30ec9aa

File tree

8 files changed

+16
-23
lines changed

8 files changed

+16
-23
lines changed

src/quart/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from inspect import isgenerator
1616
from types import TracebackType
1717
from typing import Any
18-
from typing import AnyStr
1918
from typing import Callable
2019
from typing import cast
2120
from typing import NoReturn
@@ -1304,7 +1303,7 @@ def test_request_context(
13041303
query_string: dict | None = None,
13051304
scheme: str = "http",
13061305
send_push_promise: Callable[[str, Headers], Awaitable[None]] = no_op_push,
1307-
data: AnyStr | None = None,
1306+
data: str | bytes | None = None,
13081307
form: dict | None = None,
13091308
json: Any = sentinel,
13101309
root_path: str = "",

src/quart/asgi.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import asyncio
44
import warnings
55
from functools import partial
6-
from typing import AnyStr
76
from typing import cast
87
from typing import Optional
98
from typing import TYPE_CHECKING
@@ -306,7 +305,7 @@ async def handle_websocket(
306305
cast(WebsocketCloseEvent, {"type": "websocket.close", "code": 1000})
307306
)
308307

309-
async def send_data(self, send: ASGISendCallable, data: AnyStr) -> None:
308+
async def send_data(self, send: ASGISendCallable, data: str | bytes) -> None:
310309
if isinstance(data, str):
311310
await send({"type": "websocket.send", "bytes": None, "text": data})
312311
else:

src/quart/signals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
websocket_started = _signals.signal("websocket-started")
4545

4646
#: Called on receipt of a message over the websocket, connected
47-
# functions should have a signature of Callable[[AnyStr], None]
47+
# functions should have a signature of Callable[[str | bytes], None]
4848
websocket_received = _signals.signal("websocket-received")
4949

5050
#: Called when a message has been sent over the websocket, connected
51-
# functions should have a signature of Callable[[AnyStr], None]
51+
# functions should have a signature of Callable[[str | bytes], None]
5252
websocket_sent = _signals.signal("websocket-sent")
5353

5454
#: Called after a response is fully finalised, connected functions

src/quart/testing/client.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from http.cookiejar import CookieJar
88
from types import TracebackType
99
from typing import Any
10-
from typing import AnyStr
1110
from typing import TYPE_CHECKING
1211
from urllib.request import Request as U2Request
1312

@@ -76,7 +75,7 @@ async def open(
7675
*,
7776
method: str = "GET",
7877
headers: dict | Headers | None = None,
79-
data: AnyStr | None = None,
78+
data: str | bytes | None = None,
8079
form: dict | None = None,
8180
files: dict[str, FileStorage] | None = None,
8281
query_string: dict | None = None,
@@ -328,7 +327,7 @@ async def session_transaction(
328327
headers: dict | Headers | None = None,
329328
query_string: dict | None = None,
330329
scheme: str = "http",
331-
data: AnyStr | None = None,
330+
data: str | bytes | None = None,
332331
form: dict | None = None,
333332
json: Any = sentinel,
334333
root_path: str = "",
@@ -406,7 +405,7 @@ async def _make_request(
406405
path: str,
407406
method: str,
408407
headers: dict | Headers | None,
409-
data: AnyStr | None,
408+
data: str | bytes | None,
410409
form: dict | None,
411410
files: dict[str, FileStorage] | None,
412411
query_string: dict | None,

src/quart/testing/connections.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from collections.abc import Awaitable
55
from types import TracebackType
66
from typing import Any
7-
from typing import AnyStr
87
from typing import TYPE_CHECKING
98

109
from hypercorn.typing import ASGIReceiveEvent
@@ -146,14 +145,14 @@ async def __aexit__(
146145
):
147146
raise data
148147

149-
async def receive(self) -> AnyStr:
148+
async def receive(self) -> str | bytes:
150149
data = await self._receive_queue.get()
151150
if isinstance(data, Exception):
152151
raise data
153152
else:
154153
return data
155154

156-
async def send(self, data: AnyStr) -> None:
155+
async def send(self, data: str | bytes) -> None:
157156
if isinstance(data, str):
158157
await self._send_queue.put({"type": "websocket.receive", "text": data})
159158
else:

src/quart/testing/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
from typing import Any
4-
from typing import AnyStr
54
from typing import cast
65
from typing import Literal
76
from typing import overload
@@ -80,7 +79,7 @@ def make_test_headers_path_and_query_string(
8079

8180
def make_test_body_with_headers(
8281
*,
83-
data: AnyStr | None = None,
82+
data: str | bytes | None = None,
8483
form: dict | None = None,
8584
files: dict[str, FileStorage] | None = None,
8685
json: Any = sentinel,

src/quart/typing.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from http.cookiejar import CookieJar
1414
from types import TracebackType
1515
from typing import Any
16-
from typing import AnyStr
1716
from typing import Callable
1817
from typing import Optional
1918
from typing import TYPE_CHECKING
@@ -182,9 +181,9 @@ async def __aexit__(
182181
self, exc_type: type, exc_value: BaseException, tb: TracebackType
183182
) -> None: ...
184183

185-
async def receive(self) -> AnyStr: ...
184+
async def receive(self) -> str | bytes: ...
186185

187-
async def send(self, data: AnyStr) -> None: ...
186+
async def send(self, data: str | bytes) -> None: ...
188187

189188
async def receive_json(self) -> Any: ...
190189

@@ -210,7 +209,7 @@ async def open(
210209
*,
211210
method: str = "GET",
212211
headers: dict | Headers | None = None,
213-
data: AnyStr | None = None,
212+
data: str | bytes | None = None,
214213
form: dict | None = None,
215214
files: dict[str, FileStorage] | None = None,
216215
query_string: dict | None = None,
@@ -297,7 +296,7 @@ def session_transaction(
297296
headers: dict | Headers | None = None,
298297
query_string: dict | None = None,
299298
scheme: str = "http",
300-
data: AnyStr | None = None,
299+
data: str | bytes | None = None,
301300
form: dict | None = None,
302301
json: Any = None,
303302
root_path: str = "",

src/quart/wrappers/websocket.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import asyncio
44
from typing import Any
5-
from typing import AnyStr
65
from typing import Callable
76

87
from hypercorn.typing import WebsocketScope
@@ -55,11 +54,11 @@ def __init__(
5554
def requested_subprotocols(self) -> list[str]:
5655
return self._subprotocols
5756

58-
async def receive(self) -> AnyStr:
57+
async def receive(self) -> str | bytes:
5958
await self.accept()
6059
return await self._receive()
6160

62-
async def send(self, data: AnyStr) -> None:
61+
async def send(self, data: str | bytes) -> None:
6362
# Must allow for the event loop to act if the user has say
6463
# setup a tight loop sending data over a websocket (as in the
6564
# example). So yield via the sleep.

0 commit comments

Comments
 (0)