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) (#3272)

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

Please sign in to comment.