Skip to content

Commit fff2a17

Browse files
authored
fix!: bump httpx-ws >= 0.7.1 to fix frankie567/httpx-ws#29 (#49)
* fix!: bump `httpx-ws >= 0.7.1` to fix frankie567/httpx-ws#29 Drop Python 3.8 support. Add support for Python 3.13. It's because `httpx-ws >= 0.7` not longer supports Python 3.8. BREAKING CHANGE: Drop Python 3.8 support. * docs(CHANGELOG): update `CHANGELOG.md`
1 parent 558a86b commit fff2a17

File tree

13 files changed

+44
-43
lines changed

13 files changed

+44
-43
lines changed

.github/workflows/lint-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
python_version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
21+
python_version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
2222
steps:
2323
- uses: actions/checkout@v4
2424
- name: Set up Python
@@ -38,7 +38,7 @@ jobs:
3838
strategy:
3939
fail-fast: false
4040
matrix:
41-
python_version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
41+
python_version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
4242
os: ["ubuntu-latest", "windows-latest"]
4343
steps:
4444
- uses: actions/checkout@v4

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727

2828
- [#30](https://github.com/WSH032/fastapi-proxy-lib/pull/30) - fix(internal): use `websocket` in favor of `websocket_route`. Thanks [@WSH032](https://github.com/WSH032)!
2929

30+
### Removed
31+
32+
- [#49](https://github.com/WSH032/fastapi-proxy-lib/pull/49) - Drop support for `Python 3.8`.
33+
34+
### Fixed
35+
36+
- [#49](https://github.com/WSH032/fastapi-proxy-lib/pull/49) - fix!: bump `httpx-ws >= 0.7.1` to fix frankie567/httpx-ws#29. Thanks [@WSH032](https://github.com/WSH032)!
37+
3038
### Internal
3139

3240
- [#47](https://github.com/WSH032/fastapi-proxy-lib/pull/47) - test: do not use deprecated and removed APIs of httpx. Thanks [@WSH032](https://github.com/WSH032)!

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
55
# https://hatch.pypa.io/latest/config/metadata/
66
[project]
77
name = "fastapi-proxy-lib"
8-
requires-python = ">=3.8"
8+
requires-python = ">=3.9"
99
readme = "README.md"
1010
license = { file = "LICENSE" }
1111
authors = [
@@ -29,11 +29,11 @@ classifiers = [
2929
"License :: OSI Approved :: Apache Software License",
3030
"Operating System :: OS Independent",
3131
"Intended Audience :: Developers",
32-
"Programming Language :: Python :: 3.8",
3332
"Programming Language :: Python :: 3.9",
3433
"Programming Language :: Python :: 3.10",
3534
"Programming Language :: Python :: 3.11",
3635
"Programming Language :: Python :: 3.12",
36+
"Programming Language :: Python :: 3.13",
3737
"Programming Language :: Python :: 3 :: Only",
3838
"Topic :: Internet :: WWW/HTTP :: HTTP Servers",
3939
"Topic :: Internet :: WWW/HTTP :: Session",
@@ -50,7 +50,7 @@ dynamic = ["version"]
5050

5151
dependencies = [
5252
"httpx",
53-
"httpx-ws >= 0.4.2",
53+
"httpx-ws >= 0.7.1",
5454
"starlette",
5555
"typing_extensions >=4.5.0",
5656
]
@@ -202,7 +202,7 @@ convention = "google"
202202
# https://microsoft.github.io/pyright/#/configuration
203203
[tool.pyright]
204204
typeCheckingMode = "strict"
205-
pythonVersion = "3.8"
205+
pythonVersion = "3.9"
206206
reportUnusedImport = "warning"
207207
reportUnusedFunction = "warning"
208208
reportUnusedExpression = "warning"

scripts/pre_commit_scripts/ver_sync.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
from pathlib import Path
1414
from typing import (
1515
Any,
16-
Dict,
17-
List,
1816
Union,
1917
)
2018

@@ -30,24 +28,24 @@
3028
pre_commit_config_yaml_path = Path(".pre-commit-config.yaml")
3129
pyproject_toml_path = Path("pyproject.toml")
3230

33-
RepoType = Dict[str, Any]
34-
HookType = Dict[str, Any]
31+
RepoType = dict[str, Any]
32+
HookType = dict[str, Any]
3533

3634
if __name__ == "__main__":
3735
# NOTE: 这三个键名应该对应
3836
# pyproject_toml["tool"]["hatch"]["envs"]["default"]["dependencies"] 里的值
39-
vers_in_pre_commit: Dict[str, Union[None, str]] = {
37+
vers_in_pre_commit: dict[str, Union[None, str]] = {
4038
"ruff": None,
4139
"black": None,
4240
"codespell": None,
4341
}
4442

4543
# 找出pre-commit-config.yaml中的版本
4644
pre_commit_yaml = yaml.load(pre_commit_config_yaml_path)
47-
repos_lst: List[RepoType] = pre_commit_yaml["repos"]
45+
repos_lst: list[RepoType] = pre_commit_yaml["repos"]
4846

4947
for repo in repos_lst:
50-
hooks_lst: List[HookType] = repo["hooks"]
48+
hooks_lst: list[HookType] = repo["hooks"]
5149
hook = hooks_lst[0] # 特殊标记的只有一个hook
5250
hook_alias = hook.get("alias") # 只有特殊标记的才有alias
5351
if hook_alias is None:
@@ -56,7 +54,7 @@
5654
vers_in_pre_commit[hook_alias] = repo["rev"]
5755

5856
# 检查是否正确
59-
new_vers: Dict[str, Version] = {}
57+
new_vers: dict[str, Version] = {}
6058
for name, ver in vers_in_pre_commit.items():
6159
if not isinstance(ver, str):
6260
sys.exit(f"Error: version of `{name}` not found in pre-commit-config.yaml")

src/fastapi_proxy_lib/core/_tool.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
import ipaddress
44
import logging
55
import warnings
6+
from collections.abc import Iterable, Mapping
67
from functools import lru_cache
78
from textwrap import dedent
89
from typing import (
910
Any,
10-
Iterable,
11-
Mapping,
1211
Optional,
1312
Protocol,
1413
TypedDict,

src/fastapi_proxy_lib/core/http.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from textwrap import dedent
55
from typing import (
66
Any,
7-
List,
87
NamedTuple,
98
NoReturn,
109
Optional,
@@ -185,7 +184,7 @@ def _change_server_header(
185184
Returns:
186185
The **oringinal headers**, but **had been changed**.
187186
"""
188-
server_connection_header: List[str] = [
187+
server_connection_header: list[str] = [
189188
v.strip() for v in headers.get("connection", "").lower().split(",")
190189
]
191190

src/fastapi_proxy_lib/core/websocket.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import (
77
TYPE_CHECKING,
88
Any,
9-
List,
109
Literal,
1110
NamedTuple,
1211
NoReturn,
@@ -80,7 +79,7 @@ class _ClientServerProxyTask(NamedTuple):
8079
_change_client_header = change_necessary_client_header_for_httpx
8180

8281

83-
def _get_client_request_subprotocols(ws_scope: Scope) -> Union[List[str], None]:
82+
def _get_client_request_subprotocols(ws_scope: Scope) -> Union[list[str], None]:
8483
"""Get client request subprotocols.
8584
8685
Args:
@@ -91,7 +90,7 @@ def _get_client_request_subprotocols(ws_scope: Scope) -> Union[List[str], None]:
9190
Else return `None`.
9291
"""
9392
# https://asgi.readthedocs.io/en/latest/specs/www.html#websocket-connection-scope
94-
subprotocols: List[str] = ws_scope.get("subprotocols", [])
93+
subprotocols: list[str] = ws_scope.get("subprotocols", [])
9594
if not subprotocols: # 即为 []
9695
return None
9796
return subprotocols
@@ -484,7 +483,7 @@ async def send_request_to_target( # pyright: ignore [reportIncompatibleMethodOv
484483
keepalive_ping_interval_seconds = self.keepalive_ping_interval_seconds
485484
keepalive_ping_timeout_seconds = self.keepalive_ping_timeout_seconds
486485

487-
client_request_subprotocols: Union[List[str], None] = (
486+
client_request_subprotocols: Union[list[str], None] = (
488487
_get_client_request_subprotocols(websocket.scope)
489488
)
490489

src/fastapi_proxy_lib/fastapi/router.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55

66
import asyncio
77
import warnings
8-
from contextlib import asynccontextmanager
8+
from collections.abc import AsyncIterator
9+
from contextlib import AbstractAsyncContextManager, asynccontextmanager
910
from typing import (
1011
Any,
11-
AsyncContextManager,
12-
AsyncIterator,
1312
Callable,
1413
Literal,
1514
Optional,
16-
Set,
1715
TypeVar,
1816
Union,
1917
)
@@ -170,13 +168,13 @@ class RouterHelper:
170168

171169
def __init__(self) -> None:
172170
"""Initialize RouterHelper."""
173-
self._registered_proxy: Set[Union[_HttpProxyTypes, _WebSocketProxyTypes]] = (
171+
self._registered_proxy: set[Union[_HttpProxyTypes, _WebSocketProxyTypes]] = (
174172
set()
175173
)
176-
self._registered_router_id: Set[int] = set()
174+
self._registered_router_id: set[int] = set()
177175

178176
@property
179-
def registered_proxy(self) -> Set[Union[_HttpProxyTypes, _WebSocketProxyTypes]]:
177+
def registered_proxy(self) -> set[Union[_HttpProxyTypes, _WebSocketProxyTypes]]:
180178
"""The proxy that has been registered."""
181179
return self._registered_proxy
182180

@@ -253,7 +251,7 @@ def register_router(
253251
self._registered_proxy.add(proxy)
254252
return router
255253

256-
def get_lifespan(self) -> Callable[..., AsyncContextManager[None]]:
254+
def get_lifespan(self) -> Callable[..., AbstractAsyncContextManager[None]]:
257255
"""The lifespan event for closing registered proxy.
258256
259257
Returns:

tests/app/echo_http_app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# pyright: reportUnusedFunction=false
33

44
import io
5-
from typing import Literal, Mapping, Union
5+
from collections.abc import Mapping
6+
from typing import Literal, Union
67

78
from fastapi import FastAPI, Request, Response
89
from fastapi.responses import StreamingResponse

tests/app/tool.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import asyncio
44
import socket
55
from dataclasses import dataclass
6-
from typing import Any, Callable, List, Optional, Type, TypedDict, TypeVar, Union
6+
from typing import Any, Callable, Optional, TypedDict, TypeVar, Union
77

88
import httpx
99
import uvicorn
@@ -12,7 +12,7 @@
1212
from starlette.websockets import WebSocket
1313
from typing_extensions import Self, override
1414

15-
_Decoratable_T = TypeVar("_Decoratable_T", bound=Union[Callable[..., Any], Type[Any]])
15+
_Decoratable_T = TypeVar("_Decoratable_T", bound=Union[Callable[..., Any], type[Any]])
1616

1717
ServerRecvRequestsTypes = Union[Request, WebSocket]
1818

@@ -100,7 +100,7 @@ def __init__(
100100
self.contx_exit_timeout = contx_exit_timeout
101101

102102
@override
103-
async def startup(self, sockets: Optional[List[socket.socket]] = None) -> None:
103+
async def startup(self, sockets: Optional[list[socket.socket]] = None) -> None:
104104
"""The same as `uvicorn.Server.startup`."""
105105
super_return = await super().startup(sockets=sockets)
106106
self.contx_server_started_event.set()

0 commit comments

Comments
 (0)