Skip to content

Commit 55cbba9

Browse files
authored
Support Python 3.13 (#2662)
* Support Python 3.13 * Use `exc_type_str` instead of `exc_type.__name__` * Close GzipFile * min changes
1 parent e46165a commit 55cbba9

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

.github/workflows/test-suite.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
strategy:
1616
matrix:
17-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
17+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
1818

1919
steps:
2020
- uses: "actions/checkout@v4"

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ classifiers = [
2323
"Programming Language :: Python :: 3.10",
2424
"Programming Language :: Python :: 3.11",
2525
"Programming Language :: Python :: 3.12",
26+
"Programming Language :: Python :: 3.13",
2627
"Topic :: Internet :: WWW/HTTP",
2728
]
2829
dependencies = [

starlette/middleware/errors.py

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

33
import html
44
import inspect
5+
import sys
56
import traceback
67
import typing
78

@@ -237,11 +238,13 @@ def generate_html(self, exc: Exception, limit: int = 7) -> str:
237238
exc_html += self.generate_frame_html(frame, is_collapsed)
238239
is_collapsed = True
239240

241+
if sys.version_info >= (3, 13): # pragma: no cover
242+
exc_type_str = traceback_obj.exc_type_str
243+
else: # pragma: no cover
244+
exc_type_str = traceback_obj.exc_type.__name__
245+
240246
# escape error class and text
241-
error = (
242-
f"{html.escape(traceback_obj.exc_type.__name__)}: "
243-
f"{html.escape(str(traceback_obj))}"
244-
)
247+
error = f"{html.escape(exc_type_str)}: {html.escape(str(traceback_obj))}"
245248

246249
return TEMPLATE.format(styles=STYLES, js=JS, error=error, exc_html=exc_html)
247250

starlette/middleware/gzip.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def __init__(self, app: ASGIApp, minimum_size: int, compresslevel: int = 9) -> N
4141

4242
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
4343
self.send = send
44-
await self.app(scope, receive, self.send_with_gzip)
44+
with self.gzip_buffer, self.gzip_file:
45+
await self.app(scope, receive, self.send_with_gzip)
4546

4647
async def send_with_gzip(self, message: Message) -> None:
4748
message_type = message["type"]

0 commit comments

Comments
 (0)