Skip to content

Commit a5f706f

Browse files
authored
docs(python): replace List with Sequence for immutable returns (#417)
1 parent bf4887c commit a5f706f

File tree

5 files changed

+40
-40
lines changed

5 files changed

+40
-40
lines changed

python/rnet/__init__.pyi

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import datetime
2-
import ipaddress
2+
from ipaddress import IPv4Address, IPv6Address
33
from typing import (
44
AsyncGenerator,
55
Generator,
66
Optional,
77
Tuple,
88
Any,
99
Dict,
10-
List,
10+
Sequence,
1111
TypedDict,
1212
Unpack,
1313
NotRequired,
@@ -101,7 +101,7 @@ class SocketAddr:
101101
"""
102102

103103
def __str__(self) -> str: ...
104-
def ip(self) -> ipaddress.IPv4Address | ipaddress.IPv6Address:
104+
def ip(self) -> IPv4Address | IPv6Address:
105105
r"""
106106
Returns the IP address of the socket address.
107107
"""
@@ -446,7 +446,7 @@ class Response:
446446
Get the headers of the response.
447447
"""
448448

449-
cookies: List[Cookie]
449+
cookies: Sequence[Cookie]
450450
r"""
451451
Get the cookies of the response.
452452
"""
@@ -466,7 +466,7 @@ class Response:
466466
Get the local address of the response.
467467
"""
468468

469-
history: List[History]
469+
history: Sequence[History]
470470
r"""
471471
Get the redirect history of the Response.
472472
"""
@@ -536,7 +536,7 @@ class WebSocket:
536536
Get the headers of the response.
537537
"""
538538

539-
cookies: List[Cookie]
539+
cookies: Sequence[Cookie]
540540
r"""
541541
Get the cookies of the response.
542542
"""
@@ -563,7 +563,7 @@ class WebSocket:
563563
Send a message to the WebSocket.
564564
"""
565565

566-
async def send_all(self, messages: List[Message]) -> None:
566+
async def send_all(self, messages: Sequence[Message]) -> None:
567567
r"""
568568
Send multiple messages to the WebSocket.
569569
"""
@@ -594,7 +594,7 @@ class ClientParams(TypedDict):
594594
Default request headers.
595595
"""
596596

597-
orig_headers: NotRequired[List[str] | OrigHeaderMap]
597+
orig_headers: NotRequired[Sequence[str] | OrigHeaderMap]
598598
"""
599599
Original request headers (case-sensitive and order).
600600
"""
@@ -771,12 +771,12 @@ class ClientParams(TypedDict):
771771
Disable proxy.
772772
"""
773773

774-
proxies: NotRequired[List[Proxy]]
774+
proxies: NotRequired[Sequence[Proxy]]
775775
"""
776776
Proxy server list.
777777
"""
778778

779-
local_address: NotRequired[str | ipaddress.IPv4Address | ipaddress.IPv6Address]
779+
local_address: NotRequired[str | IPv4Address | IPv6Address]
780780
"""
781781
Local bind address.
782782
"""
@@ -823,7 +823,7 @@ class Request(TypedDict):
823823
The proxy to use for the request.
824824
"""
825825

826-
local_address: NotRequired[ipaddress.IPv4Address | ipaddress.IPv6Address]
826+
local_address: NotRequired[IPv4Address | IPv6Address]
827827
"""
828828
Bind to a local IP Address.
829829
"""
@@ -853,7 +853,7 @@ class Request(TypedDict):
853853
The headers to use for the request.
854854
"""
855855

856-
orig_headers: NotRequired[List[str] | OrigHeaderMap]
856+
orig_headers: NotRequired[Sequence[str] | OrigHeaderMap]
857857
"""
858858
The original headers to use for the request.
859859
"""
@@ -913,12 +913,12 @@ class Request(TypedDict):
913913
The basic authentication to use for the request.
914914
"""
915915

916-
query: NotRequired[List[Tuple[str, str]] | Dict[str, str]]
916+
query: NotRequired[Sequence[Tuple[str, str]] | Dict[str, str]]
917917
"""
918918
The query parameters to use for the request.
919919
"""
920920

921-
form: NotRequired[List[Tuple[str, str]] | Dict[str, str]]
921+
form: NotRequired[Sequence[Tuple[str, str]] | Dict[str, str]]
922922
"""
923923
The form parameters to use for the request.
924924
"""
@@ -931,9 +931,9 @@ class Request(TypedDict):
931931
body: NotRequired[
932932
str
933933
| bytes
934-
| list[tuple[str, str]]
935-
| dict[str, str]
936-
| dict[str, Any]
934+
| Sequence[Tuple[str, str]]
935+
| Dict[str, str]
936+
| Dict[str, Any]
937937
| Generator[bytes, str, None]
938938
| AsyncGenerator[bytes, str]
939939
]
@@ -957,7 +957,7 @@ class WebSocketRequest(TypedDict):
957957
The proxy to use for the request.
958958
"""
959959

960-
local_address: NotRequired[str | ipaddress.IPv4Address | ipaddress.IPv6Address]
960+
local_address: NotRequired[str | IPv4Address | IPv6Address]
961961
"""
962962
Bind to a local IP Address.
963963
"""
@@ -972,7 +972,7 @@ class WebSocketRequest(TypedDict):
972972
The headers to use for the request.
973973
"""
974974

975-
orig_headers: NotRequired[List[str] | OrigHeaderMap]
975+
orig_headers: NotRequired[Sequence[str] | OrigHeaderMap]
976976
"""
977977
The original headers to use for the request.
978978
"""
@@ -987,7 +987,7 @@ class WebSocketRequest(TypedDict):
987987
The cookies to use for the request.
988988
"""
989989

990-
protocols: NotRequired[List[str]]
990+
protocols: NotRequired[Sequence[str]]
991991
"""
992992
The protocols to use for the request.
993993
"""
@@ -1012,7 +1012,7 @@ class WebSocketRequest(TypedDict):
10121012
The basic authentication to use for the request.
10131013
"""
10141014

1015-
query: NotRequired[List[Tuple[str, str]]]
1015+
query: NotRequired[Sequence[Tuple[str, str]]]
10161016
"""
10171017
The query parameters to use for the request.
10181018
"""

python/rnet/blocking.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from typing import (
1515
Optional,
1616
Any,
17-
List,
17+
Sequence,
1818
Unpack,
1919
)
2020

@@ -47,7 +47,7 @@ class Response:
4747
Get the headers of the response.
4848
"""
4949

50-
cookies: List[Cookie]
50+
cookies: Sequence[Cookie]
5151
r"""
5252
Get the cookies of the response.
5353
"""
@@ -67,7 +67,7 @@ class Response:
6767
Get the local address of the response.
6868
"""
6969

70-
history: List[History]
70+
history: Sequence[History]
7171
r"""
7272
Get the redirect history of the Response.
7373
"""
@@ -140,7 +140,7 @@ class WebSocket:
140140
Get the headers of the response.
141141
"""
142142

143-
cookies: List[Cookie]
143+
cookies: Sequence[Cookie]
144144
r"""
145145
Get the cookies of the response.
146146
"""
@@ -169,13 +169,13 @@ def send(self, message: Message) -> None:
169169
* `message` - The message to send.
170170
"""
171171

172-
def send_all(self, messages: List[Message]) -> None:
172+
def send_all(self, messages: Sequence[Message]) -> None:
173173
r"""
174174
Send multiple messages to the WebSocket.
175175
176176
# Arguments
177177
178-
* `messages` - The list of messages to send.
178+
* `messages` - The sequence of messages to send.
179179
"""
180180

181181
def close(

python/rnet/cookie.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import datetime
1010
from enum import Enum, auto
11-
from typing import List, Optional, final
11+
from typing import Optional, Sequence, final
1212

1313
__all__ = ["SameSite", "Cookie", "Jar"]
1414

@@ -110,7 +110,7 @@ def get(self, name: str, url: str) -> Optional[Cookie]:
110110
"""
111111
...
112112

113-
def get_all(self) -> List[Cookie]:
113+
def get_all(self) -> Sequence[Cookie]:
114114
r"""
115115
Get all cookies.
116116
"""

python/rnet/header.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Set-Cookie, Accept-Encoding, etc.).
1212
"""
1313

14-
from typing import Dict, Iterator, List, Optional, Tuple
14+
from typing import Dict, Iterator, Optional, Sequence, Tuple
1515

1616
__all__ = ["HeaderMap", "OrigHeaderMap"]
1717

@@ -265,7 +265,7 @@ class OrigHeaderMap:
265265

266266
def __init__(
267267
self,
268-
init: Optional[List[str]] = None,
268+
init: Optional[Sequence[str]] = None,
269269
capacity: Optional[int] = None,
270270
) -> None:
271271
"""

python/rnet/tls.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from enum import Enum, auto
1010
from pathlib import Path
11-
from typing import List, NotRequired, TypedDict, Unpack, final
11+
from typing import Sequence, NotRequired, TypedDict, Unpack, final
1212

1313
__all__ = [
1414
"TlsVersion",
@@ -152,8 +152,8 @@ class CertStore:
152152

153153
def __init__(
154154
self,
155-
der_certs: List[bytes] | None = None,
156-
pem_certs: List[str] | None = None,
155+
der_certs: Sequence[bytes] | None = None,
156+
pem_certs: Sequence[str] | None = None,
157157
default_paths: bool | None = None,
158158
) -> None:
159159
"""
@@ -167,7 +167,7 @@ def __init__(
167167
...
168168

169169
@staticmethod
170-
def from_der_certs(certs: List[bytes]) -> "CertStore":
170+
def from_der_certs(certs: Sequence[bytes]) -> "CertStore":
171171
"""
172172
Creates a CertStore from a collection of DER-encoded certificates.
173173
@@ -177,7 +177,7 @@ def from_der_certs(certs: List[bytes]) -> "CertStore":
177177
...
178178

179179
@staticmethod
180-
def from_pem_certs(certs: List[str]) -> "CertStore":
180+
def from_pem_certs(certs: Sequence[str]) -> "CertStore":
181181
"""
182182
Creates a CertStore from a collection of PEM-encoded certificates.
183183
@@ -243,15 +243,15 @@ class Params(TypedDict):
243243
All parameters for TLS connections.
244244
"""
245245

246-
alpn_protocols: NotRequired[List[AlpnProtocol]]
246+
alpn_protocols: NotRequired[Sequence[AlpnProtocol]]
247247
"""
248248
Application-Layer Protocol Negotiation (RFC 7301).
249249
250250
Specifies which application protocols (e.g., HTTP/2, HTTP/1.1) may be negotiated
251251
over a single TLS connection.
252252
"""
253253

254-
alps_protocols: NotRequired[List[AlpsProtocol]]
254+
alps_protocols: NotRequired[Sequence[AlpsProtocol]]
255255
"""
256256
Application-Layer Protocol Settings (ALPS).
257257
@@ -369,13 +369,13 @@ class Params(TypedDict):
369369
"""
370370

371371
certificate_compression_algorithms: NotRequired[
372-
List[CertificateCompressionAlgorithm]
372+
Sequence[CertificateCompressionAlgorithm]
373373
]
374374
"""
375375
Supported certificate compression algorithms (RFC 8879).
376376
"""
377377

378-
extension_permutation: NotRequired[List[ExtensionType]]
378+
extension_permutation: NotRequired[Sequence[ExtensionType]]
379379
"""
380380
Supported TLS extensions, used for extension ordering/permutation.
381381
"""

0 commit comments

Comments
 (0)