Skip to content

Commit

Permalink
Support Python 3.13 (#2662)
Browse files Browse the repository at this point in the history
* Support Python 3.13

* Use `exc_type_str` instead of `exc_type.__name__`

* Close GzipFile

* min changes
  • Loading branch information
Kludex committed Aug 6, 2024
1 parent e46165a commit 55cbba9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: "actions/checkout@v4"
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Internet :: WWW/HTTP",
]
dependencies = [
Expand Down
11 changes: 7 additions & 4 deletions starlette/middleware/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import html
import inspect
import sys
import traceback
import typing

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

if sys.version_info >= (3, 13): # pragma: no cover
exc_type_str = traceback_obj.exc_type_str
else: # pragma: no cover
exc_type_str = traceback_obj.exc_type.__name__

# escape error class and text
error = (
f"{html.escape(traceback_obj.exc_type.__name__)}: "
f"{html.escape(str(traceback_obj))}"
)
error = f"{html.escape(exc_type_str)}: {html.escape(str(traceback_obj))}"

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

Expand Down
3 changes: 2 additions & 1 deletion starlette/middleware/gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def __init__(self, app: ASGIApp, minimum_size: int, compresslevel: int = 9) -> N

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

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

0 comments on commit 55cbba9

Please sign in to comment.