ref: Remove Python 2 compat from qualname_from_function#6137
ref: Remove Python 2 compat from qualname_from_function#6137ericapisani wants to merge 1 commit intomasterfrom
Conversation
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>
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 7.57s All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 14783 uncovered lines. Files with missing lines (1)
Generated by Codecov Action |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6d4e045. Configure here.
| ) | ||
| except Exception: | ||
| pass | ||
|
|
There was a problem hiding this comment.
Fallback removal breaks built-in function name resolution
Medium Severity
The removed elif hasattr(func, "__name__") fallback was labeled as Python 2 compatibility, but it also handles Python 3 builtin_function_or_method objects (e.g., len, print) and method_descriptor objects (e.g., str.strip), which have __name__ but not __qualname__ (confirmed by CPython issue #57786). After this change, qualname_from_function returns None instead of a name string for any such callable. While current callers mostly pass user-defined functions, the function's contract is silently narrowed.
Reviewed by Cursor Bugbot for commit 6d4e045. Configure here.
There was a problem hiding this comment.
This is somewhat incorrect.
The issue that it's referencing is python/cpython#57786 , which relates to Python 3.3 (and we support 3.6+).
Where I can see this being correct is that if a custom class has a __name__ defined, but not a __qualname__, this would no longer work without adding the :
if hasattr(func, "__name__"):
func_qualname = func.__name__logic back in.
Will come back to this on Monday.


Remove two Python 2 compatibility branches from
sentry_sdk/utils.py::qualname_from_functionthat can never fire.The SDK requires Python ≥ 3.6 (
setup.py), so theim_classtry/except(Python 2 bound-method attribute) and theelif hasattr(func, "__name__")fallback annotated# Python 2.7 has no __qualname__are dead code.No behavior change for any Python 3 input — the return contract is preserved for callers in
tracing_utils.py,integrations/ray.py,integrations/asgi.py, andintegrations/django/tasks.py.Refs PY-2298