gh-130821: Add type info to error message in Modules/_abc.c - #156120
Closed
JMak-Security wants to merge 1 commit into
Closed
gh-130821: Add type info to error message in Modules/_abc.c#156120JMak-Security wants to merge 1 commit into
JMak-Security wants to merge 1 commit into
Conversation
When an item yielded by a class namespace's items() is not iterable during abstract-method computation, include the type of the offending item in the raised TypeError, matching the type-information convention established in pythongh-130835. This targets the same _abc.c hunk that pythongh-144737 (now stale) proposed, using PyErr_ExceptionMatches to only replace the message on a genuine TypeError instead of passing NULL through PySequence_Fast, which risks a NULL PyErr_SetString call if that path is ever reached with a different underlying error.
Member
|
A stale PR does not mean we would not reconsider it. Should you reope once again a PR just for cherry picking a specific part, we will restrict your access. |
Author
|
Noted, I won't reopen or split off pieces of an existing/stale PR like that again. Appreciate the heads up. |
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.
Supersedes the
Modules/_abc.cportion of gh-144737, which has gone stale (no activity since a 2026-05-06 stale-bot ping, still unmerged). This picks up that piece specifically, using the type-information convention established by the merged gh-130835.Change
When an item yielded by a class namespace's
items()isn't iterable during abstract-method computation, the raisedTypeErrornow includes the offending item's type:Why not just reuse gh-144737's diff verbatim
gh-144737's
_abc.chunk passesNULLas the message argument toPySequence_Fast():PySequence_Fast()callsPyErr_SetString()with that message when the failure is aTypeError, andPyErr_SetString(exc, NULL)dereferences a nullchar *insidePyUnicode_FromString(). This is reachable ifself.__dict__(ornsfrom a custom metaclass namespace) yields an item that isn't iterable and whose iteration failure is aTypeError— the exact case this PR is fixing.This PR instead keeps a real fallback message on
PySequence_Fast()and only replaces it viaPyErr_Format()after checkingPyErr_ExceptionMatches(PyExc_TypeError), so no NULL ever reachesPyErr_SetString(), and non-TypeError failures (e.g. a raising__iter__) propagate unmodified instead of being overwritten.Scope
This intentionally covers only
Modules/_abc.c, not the other six files gh-144737 touched (_csv.c,_datetimemodule.c,_io/*.c,_pickle.c). That PR's_pickle.chunk had an open reviewer question (ValueError vs. TypeError forread()'s return-type check) that never reached a resolution, and gh-130821 itself is still marked by @serhiy-storchaka as needing wider consensus for a repo-wide sweep (see the stalled https://discuss.python.org/t/error-messages-for-methods/83362). Keeping this PR narrow avoids re-opening either of those unresolved questions.