Skip to content

Commit

Permalink
fix(utils): Handle partialmethod in qualname_from_function (CPyth…
Browse files Browse the repository at this point in the history
…on 3.13)

The `_partialmethod` attribute of methods wrapped with `partialmethod()`
was renamed to `__partialmethod__` in CPython 3.13:
python/cpython#16600
  • Loading branch information
rominf committed Jul 10, 2024
1 parent 4f5fe0a commit a193ad4
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,14 +1330,19 @@ 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:
# 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(<function ", ">)"
func = partial_method.func

if hasattr(func, "__qualname__"):
func_qualname = func.__qualname__
Expand Down

0 comments on commit a193ad4

Please sign in to comment.