python-sentry-sdk/0004-fix-utils-Handle-partialmethod-in-qualname_from_func.patch
2024-08-20 07:48:25 +03:00

43 lines
1.7 KiB
Diff

From a87d055571b0ae496b60d4e833f64b925e5f9563 Mon Sep 17 00:00:00 2001
From: Roman Inflianskas <rominf@pm.me>
Date: Fri, 5 Jul 2024 16:38:32 +0300
Subject: [PATCH] fix(utils): Handle `partialmethod` in qualname_from_function
(CPython 3.13)
`_partialmethod` attribute of methods wrapped with `partialmethod()` was
renamed to `__partialmethod__` in CPython 3.13:
https://github.com/python/cpython/pull/16600
---
sentry_sdk/utils.py | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py
index 64bbd383..262f4f97 100644
--- a/sentry_sdk/utils.py
+++ b/sentry_sdk/utils.py
@@ -1329,14 +1329,16 @@ def qualname_from_function(func):
prefix, suffix = "", ""
- if hasattr(func, "_partialmethod") and isinstance(
- func._partialmethod, partialmethod
- ):
- prefix, suffix = "partialmethod(<function ", ">)"
- func = func._partialmethod.func
- elif isinstance(func, partial) and hasattr(func.func, "__name__"):
+ if isinstance(func, partial) and hasattr(func.func, "__name__"):
prefix, suffix = "partial(<function ", ">)"
func = func.func
+ else:
+ # _partialmethod attribute of methods wrapped with partialmethod() was renamed to __partialmethod__ in CPython 3.13:
+ # https://github.com/python/cpython/pull/16600
+ partial_method = getattr(func, "_partialmethod", None) or getattr(func, "__partialmethod__", None)
+ if isinstance(partial_method, partialmethod):
+ prefix, suffix = "partialmethod(<function ", ">)"
+ func = partial_method.func
if hasattr(func, "__qualname__"):
func_qualname = func.__qualname__
--
2.45.2