Skip to content

Commit 09787da

Browse files
committed
feat: Preliminary support for Python 3.13 (getsentry#3200)
Partial cherry-pick of: a98f660 Adding preliminary support for Python 3.13. The `_partialmethod` attribute of methods wrapped with `partialmethod()` was renamed to `__partialmethod__` in CPython 3.13: python/cpython#16600 Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but `FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python 3.13 and later, it should be copied using a method `.copy()`. The new way of copying works the same as the old one for versions of Python prior to 3.13, according to the documentation (both copying methods produce a shallow copy). Since Python 3.13, `FrameLocalsProxy` skips items of `locals()` that have non-`str` keys; this is a CPython implementation detail, so we hence disable `test_non_string_variables` test on Python 3.13. See: https://peps.python.org/pep-0667/ python/cpython#118921 python/cpython#118923 https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13 https://docs.python.org/3/library/copy.html https://github.com/python/cpython/blame/7b413952e817ae87bfda2ac85dd84d30a6ce743b/Objects/frameobject.c#L148
1 parent 282b8f7 commit 09787da

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

sentry_sdk/consts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,4 @@ def _get_default_options():
335335
del _get_default_options
336336

337337

338-
VERSION = "1.45.1"
338+
VERSION = "1.45.2"

sentry_sdk/utils.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import threading
1212
import time
1313
from collections import namedtuple
14-
from copy import copy
1514
from decimal import Decimal
1615
from numbers import Real
1716

@@ -672,7 +671,7 @@ def serialize_frame(
672671
)
673672

674673
if include_local_variables:
675-
rv["vars"] = copy(frame.f_locals)
674+
rv["vars"] = frame.f_locals.copy()
676675

677676
return rv
678677

@@ -1414,16 +1413,18 @@ def qualname_from_function(func):
14141413

14151414
prefix, suffix = "", ""
14161415

1417-
if (
1418-
_PARTIALMETHOD_AVAILABLE
1419-
and hasattr(func, "_partialmethod")
1420-
and isinstance(func._partialmethod, partialmethod)
1421-
):
1422-
prefix, suffix = "partialmethod(<function ", ">)"
1423-
func = func._partialmethod.func
1424-
elif isinstance(func, partial) and hasattr(func.func, "__name__"):
1416+
if isinstance(func, partial) and hasattr(func.func, "__name__"):
14251417
prefix, suffix = "partial(<function ", ">)"
14261418
func = func.func
1419+
else:
1420+
# The _partialmethod attribute of methods wrapped with partialmethod() was renamed to __partialmethod__ in CPython 3.13:
1421+
# https://github.com/python/cpython/pull/16600
1422+
partial_method = getattr(func, "_partialmethod", None) or getattr(
1423+
func, "__partialmethod__", None
1424+
)
1425+
if isinstance(partial_method, partialmethod):
1426+
prefix, suffix = "partialmethod(<function ", ">)"
1427+
func = partial_method.func
14271428

14281429
if hasattr(func, "__qualname__"):
14291430
func_qualname = func.__qualname__

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def get_file_text(file_name):
2121

2222
setup(
2323
name="sentry-sdk",
24-
version="1.45.1",
24+
version="1.45.2",
2525
author="Sentry Team and Contributors",
2626
author_email="[email protected]",
2727
url="https://github.com/getsentry/sentry-python",

0 commit comments

Comments
 (0)