Skip to content

Commit 6d4e045

Browse files
ericapisaniclaude
andcommitted
ref: Remove Python 2 compat from qualname_from_function
The SDK requires Python ≥ 3.6, so the `im_class` try/except and the `__name__` fallback annotated "Python 2.7 has no __qualname__" can never fire. Dropping them also removes a broad `except Exception: pass` that could mask real bugs in the happy path. No behavior change for any Python 3 input; return contract is preserved for callers in `tracing_utils.py`, `integrations/ray.py`, `integrations/asgi.py`, and `integrations/django/tasks.py`. Refs PY-2298 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1b72b88 commit 6d4e045

1 file changed

Lines changed: 0 additions & 13 deletions

File tree

sentry_sdk/utils.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,16 +1472,6 @@ def qualname_from_function(func: "Callable[..., Any]") -> "Optional[str]":
14721472
"""Return the qualified name of func. Works with regular function, lambda, partial and partialmethod."""
14731473
func_qualname: "Optional[str]" = None
14741474

1475-
# Python 2
1476-
try:
1477-
return "%s.%s.%s" % (
1478-
func.im_class.__module__, # type: ignore
1479-
func.im_class.__name__, # type: ignore
1480-
func.__name__,
1481-
)
1482-
except Exception:
1483-
pass
1484-
14851475
prefix, suffix = "", ""
14861476

14871477
if isinstance(func, partial) and hasattr(func.func, "__name__"):
@@ -1499,10 +1489,7 @@ def qualname_from_function(func: "Callable[..., Any]") -> "Optional[str]":
14991489

15001490
if hasattr(func, "__qualname__"):
15011491
func_qualname = func.__qualname__
1502-
elif hasattr(func, "__name__"): # Python 2.7 has no __qualname__
1503-
func_qualname = func.__name__
15041492

1505-
# Python 3: methods, functions, classes
15061493
if func_qualname is not None:
15071494
if hasattr(func, "__module__") and isinstance(func.__module__, str):
15081495
func_qualname = func.__module__ + "." + func_qualname

0 commit comments

Comments
 (0)