From b9d1e3e1f2494c64e8683075c4568d40b8c1f5d3 Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Tue, 16 Jul 2024 16:22:07 +0300 Subject: [PATCH] fix(utils): Handle `partialmethod` in `qualname_from_function` (CPython 3.13) (#3272) The `_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 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index a84f2eb3de..9eb1cb3e36 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -1330,14 +1330,18 @@ def qualname_from_function(func): prefix, suffix = "", "" - if hasattr(func, "_partialmethod") and isinstance( - func._partialmethod, partialmethod - ): - prefix, suffix = "partialmethod()" - 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()" func = func.func + else: + # The _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()" + func = partial_method.func if hasattr(func, "__qualname__"): func_qualname = func.__qualname__