Do not swallow non-TypeError exceptions in feature-detection fallbacks#1382
Open
devdanzin wants to merge 3 commits into
Open
Do not swallow non-TypeError exceptions in feature-detection fallbacks#1382devdanzin wants to merge 3 commits into
devdanzin wants to merge 3 commits into
Conversation
Several probes cleared *every* pending exception when a fallback path was taken: view richcompare and items-view __contains__ measuring len(other), items-view __contains__ computing the identity, MultiDict.__eq__ probing keys(), and extend()/ctor probing items(). A MemoryError or KeyboardInterrupt raised by the user object was silently discarded. Guard each with PyErr_ExceptionMatches() so only the expected TypeError/AttributeError is cleared and anything else propagates -- the same pattern the sibling sites in views.h already use. Adds a C-extension regression test.
…drop unused ignore)
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (90.00%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #1382 +/- ##
==========================================
- Coverage 99.86% 99.80% -0.06%
==========================================
Files 28 28
Lines 3627 3647 +20
Branches 265 265
==========================================
+ Hits 3622 3640 +18
- Misses 3 5 +2
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
What do these changes do?
Several feature-detection fallbacks cleared every pending exception when a fallback path was taken:
view richcompare and items-view
__contains__measuringlen(other), items-view__contains__computing the identity,
MultiDict.__eq__probingkeys(), andextend()/constructor probingitems(). AMemoryErrororKeyboardInterruptraised by the user object was silently discarded. Eachis now guarded with
PyErr_ExceptionMatches()so only the expectedTypeError/AttributeErroriscleared and anything else propagates — the same pattern the sibling sites in
views.halready use.C-extension-only; the pure-Python backend propagates naturally.
Are there changes in behavior for the user?
Yes (edge case): an exception other than
TypeError/AttributeError(notablyMemoryError,KeyboardInterrupt) raised by an object being probed now propagates instead of being swallowed. Thenormal fallbacks (a non-sized or non-mapping object) are unchanged.
Is it a substantial burden for the maintainers to support this?
No. It applies the module's existing guard pattern to the few sites that missed it.
Related issue number
Findings from the C-extension analysis report #1306.
Checklist
test_non_typeerror_exceptions_are_not_swallowed)CONTRIBUTORS.txtin this repoCHANGES/folder