Skip to content

ref: Remove Python 2 compat from qualname_from_function#6137

Merged
ericapisani merged 4 commits intomasterfrom
py-2298-remove-python2-compat-code-cg9li
Apr 27, 2026
Merged

ref: Remove Python 2 compat from qualname_from_function#6137
ericapisani merged 4 commits intomasterfrom
py-2298-remove-python2-compat-code-cg9li

Conversation

@ericapisani
Copy link
Copy Markdown
Member

@ericapisani ericapisani commented Apr 24, 2026

Remove two Python 2 compatibility branches from sentry_sdk/utils.py::qualname_from_function that can never fire.

The SDK requires Python ≥ 3.6 (setup.py), so the im_class try/except (Python 2 bound-method attribute) and the elif 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, and integrations/django/tasks.py.

Refs PY-2298

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>
@linear-code
Copy link
Copy Markdown

linear-code Bot commented Apr 24, 2026

@ericapisani ericapisani marked this pull request as ready for review April 24, 2026 18:59
@ericapisani ericapisani requested a review from a team as a code owner April 24, 2026 18:59
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

Codecov Results 📊

14 passed | Total: 14 | Pass Rate: 100% | Execution Time: 3.21s

All tests are passing successfully.

❌ Patch coverage is 0.00%. Project has 15927 uncovered lines.

Files with missing lines (1)
File Patch % Lines
utils.py 32.97% ⚠️ 622 Missing and 41 partials

Generated by Codecov Action

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread sentry_sdk/utils.py
Copy link
Copy Markdown
Contributor

@alexander-alderman-webb alexander-alderman-webb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for #6137 (comment)

ericapisani and others added 3 commits April 27, 2026 08:09
…have a defined, or C extension functions which only have return a value
…at may not have a `__qualname__` defined, or C extension functions which only have `__name__` return a value

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…:getsentry/sentry-python into py-2298-remove-python2-compat-code-cg9li
Copy link
Copy Markdown
Contributor

@alexander-alderman-webb alexander-alderman-webb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@ericapisani ericapisani merged commit 4455a1b into master Apr 27, 2026
165 of 167 checks passed
@ericapisani ericapisani deleted the py-2298-remove-python2-compat-code-cg9li branch April 27, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants