Skip to content

Commit 6f24f61

Browse files
committed
fix(utils): Handle partialmethod in qualname_from_function (CPython 3.13)
The `_partialmethod` attribute of methods wrapped with `partialmethod()` was renamed to `__partialmethod__` in CPython 3.13: python/cpython#16600
1 parent 4f5fe0a commit 6f24f61

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

sentry_sdk/utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,14 +1330,18 @@ def qualname_from_function(func):
13301330

13311331
prefix, suffix = "", ""
13321332

1333-
if hasattr(func, "_partialmethod") and isinstance(
1334-
func._partialmethod, partialmethod
1335-
):
1336-
prefix, suffix = "partialmethod(<function ", ">)"
1337-
func = func._partialmethod.func
1338-
elif isinstance(func, partial) and hasattr(func.func, "__name__"):
1333+
if isinstance(func, partial) and hasattr(func.func, "__name__"):
13391334
prefix, suffix = "partial(<function ", ">)"
13401335
func = func.func
1336+
else:
1337+
# The _partialmethod attribute of methods wrapped with partialmethod() was renamed to __partialmethod__ in CPython 3.13:
1338+
# https://github.com/python/cpython/pull/16600
1339+
partial_method = getattr(func, "_partialmethod", None) or getattr(
1340+
func, "__partialmethod__", None
1341+
)
1342+
if isinstance(partial_method, partialmethod):
1343+
prefix, suffix = "partialmethod(<function ", ">)"
1344+
func = partial_method.func
13411345

13421346
if hasattr(func, "__qualname__"):
13431347
func_qualname = func.__qualname__

0 commit comments

Comments
 (0)