[do not merge] ref: Remove residual Python 2 compatibility code#6091
Draft
ericapisani wants to merge 3 commits intomasterfrom
Draft
[do not merge] ref: Remove residual Python 2 compatibility code#6091ericapisani wants to merge 3 commits intomasterfrom
ericapisani wants to merge 3 commits intomasterfrom
Conversation
Python 2 support was dropped in SDK 2.0.0, but several Python 2 shims, dead branches, and stale comments remained. Clean them up: - Delete `with_metaclass()` from `_compat.py` and rewrite `class Hub(with_metaclass(HubMeta))` to use the native `metaclass=` keyword (also drops a `type: ignore`). - Remove the `im_class`/`im_func` try/except in `qualname_from_function` (unreachable on Python 3) and collapse the `__qualname__` vs `__name__` elif in both `utils.qualname_from_function` and the Django `signals_handlers._get_receiver_name` (Py3 always has `__qualname__`). - Drop the `try: ModuleNotFoundError except Exception: ImportError` shim in `client.py` — `ModuleNotFoundError` has existed since Py3.6 — and use `ModuleNotFoundError` directly at the call site. - Replace `super(_Client, self).__init__(...)` with `super().__init__(...)`. - Remove the `bdist_wheel universal=1` option from `setup.py`; universal wheels are for Py2/Py3-compatible packages and do not apply here. - Strip misleading Py2 references from comments in the Django middleware integration and in `tests/conftest.py`. No behavior change. Minimum supported Python stays at 3.6 — Python 3.6-vs-later compat code (e.g. `aiocontextvars`, `nullcontext`, `re.Pattern` fallback) is intentionally left alone. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧
Other
🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ 142 passed | Total: 142 | Pass Rate: 100% | Execution Time: 20.99s All tests are passing successfully. ❌ Patch coverage is 37.50%. Project has 14134 uncovered lines. Files with missing lines (9)
Generated by Codecov Action |
Contributor
Codecov Results 📊✅ 49 passed | ⏭️ 3 skipped | Total: 52 | Pass Rate: 94.23% | Execution Time: 12.12s 📊 Comparison with Base Branch
All tests are passing successfully. ❌ Patch coverage is 66.67%. Project has 15661 uncovered lines. Files with missing lines (6)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 31.19% 26.63% -4.56%
==========================================
Files 190 190 —
Lines 21365 21346 -19
Branches 7068 7064 -4
==========================================
+ Hits 6663 5685 -978
- Misses 14702 15661 +959
- Partials 540 490 -50Generated by Codecov Action |
Removing `bdist_wheel universal=1` from `setup.py` changed the produced wheel filename from `sentry_sdk-<ver>-py2.py3-none-any.whl` to `sentry_sdk-<ver>-py3-none-any.whl`. Update the hardcoded wheel path in `scripts/build_aws_lambda_layer.py` to match. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Follow-up to 25baa75. Removes dead-code guards that only existed to tolerate Python 2 stdlib differences: - try/except AttributeError around nanosecond_time() in Span and StreamedSpan. time.perf_counter has existed since Python 3.3 and time.perf_counter_ns since 3.7, so the exception can never fire on any supported Python 3 version. - try/except ImportError around asyncio.iscoroutinefunction in the Django integration. asyncio.iscoroutinefunction has existed since Python 3.4. - Redundant IOError in exception tuples. IOError is an alias for OSError in Python 3. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Python 2 support was dropped in SDK 2.0.0, but a handful of Python 2 shims, unreachable branches, and stale
py2comments lingered. This PR cleans them up. No behavior change.with_metaclass()fromsentry_sdk/_compat.pyand rewriteclass Hub(with_metaclass(HubMeta))to use the nativemetaclass=keyword (drops a# type: ignore).im_class/im_functry/except inqualname_from_function(unreachable on Python 3) and collapse the__qualname__vs__name__elif inutils.qualname_from_functionand Djangosignals_handlers._get_receiver_name.try: ModuleNotFoundError except Exception: ImportErrorshim inclient.pyand useModuleNotFoundErrordirectly.ModuleNotFoundErroris available in all supported Python versions (3.6+).super(_Client, self).__init__(...)withsuper().__init__(...).bdist_wheel universal=1option fromsetup.py; universal wheels are Py2/Py3-compat only.tests/conftest.py.Minimum supported Python stays at 3.6 — Python 3.6-vs-later compat (e.g.
aiocontextvars,nullcontext,re.Patternfallback,BaseExceptionGrouptry/except) is intentionally left untouched.Test plan
tox -e ruffpassestox -e mypypasses (removingwith_metaclasslets us drop the# type: ignoreonHub)tox -e py3.14-common— 2114 passed, 154 skippedHub.current/Hub.mainproperties still dispatch via theHubMetametaclass;qualname_from_functionstill resolves functions, methods, lambdas, and partials🤖 Generated with Claude Code