Skip to content

gh-130821: Make error messages consistent in Modules/ - #144737

Open
Cityfishman wants to merge 1 commit into
python:mainfrom
Cityfishman:fix-issue-130821-modules
Open

gh-130821: Make error messages consistent in Modules/#144737
Cityfishman wants to merge 1 commit into
python:mainfrom
Cityfishman:fix-issue-130821-modules

Conversation

@Cityfishman

@Cityfishman Cityfishman commented Feb 12, 2026

Copy link
Copy Markdown

Update error messages in Modules/ directory to use consistent format with %T formatter for type names, similar to changes made in PR #130835 for Objects/ directory.

Changes:

  • Modules/_abc.c: items() error message
  • Modules/_datetimemodule.c: divmod() error message
  • Modules/_pickle.c: read() error message
  • Modules/_io/bufferedio.c: read() and readall() error messages
  • Modules/_io/iobase.c: read() error message
  • Modules/_io/textio.c: decoder and encoder error messages
  • Modules/_csv.c: iterator error message

Update error messages in Modules/ directory to use consistent format
with %T formatter for type names, similar to changes made in PR python#130835
for Objects/ directory.

Changes:
- Modules/_abc.c: items() error message
- Modules/_datetimemodule.c: divmod() error message
- Modules/_pickle.c: read() error message
- Modules/_io/bufferedio.c: read() and readall() error messages
- Modules/_io/iobase.c: read() error message
- Modules/_io/textio.c: decoder and encoder error messages
- Modules/_csv.c: iterator error message
@python-cla-bot

python-cla-bot Bot commented Feb 12, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

bedevere-app Bot commented Feb 12, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Comment thread Modules/_pickle.c
@@ -1302,8 +1302,8 @@ _Unpickler_ReadIntoFromFile(PickleState *state, UnpicklerObject *self, char *buf
}
if (!PyBytes_Check(data)) {
PyErr_Format(PyExc_ValueError,

@brijkapadia brijkapadia Feb 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems strange that this raises a ValueError and not a TypeError since the error is that the return value of read() is not a bytes object, but instead a different type. Not sure the potential impact of changing this from a ValueError to a TypeError, but a TypeError feels like the better option as it makes it consistent with all the other changes in this PR and also in #130835.

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 6, 2026
JMak-Security added a commit to JMak-Security/cpython that referenced this pull request Aug 20, 2026
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.
@JMak-Security

Copy link
Copy Markdown

Since this PR has been stale since 2026-05-06 and I can't push to its branch, I've opened #156120 to pick up the Modules/_abc.c portion specifically (with a fix for a NULL-dereference risk in this PR's PySequence_Fast() call — see the PR description). I'm leaving the other six files here untouched for now since the _pickle.c ValueError/TypeError question raised in review is still unresolved and gh-130821 is still marked as needing wider consensus for a full repo-wide sweep. Happy to pick up the remaining files in follow-up PRs once that's settled, or to collaborate with @Cityfishman if they want to continue this one.

@picnixz

picnixz commented Aug 20, 2026

Copy link
Copy Markdown
Member

This is not a reason to open PRs and you should stop this as this will be considered a spam. Stale PRs can be revived

@picnixz

picnixz commented Aug 20, 2026

Copy link
Copy Markdown
Member

More precisely: I am not even sure we want this. So this either needs discussion revival or broader consensus

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants