Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-130821: Add type information to wrong type error messages#130835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
donBarbos wants to merge13 commits intopython:main
base:main
Choose a base branch
Loading
fromdonBarbos:issue-130821

Conversation

donBarbos
Copy link
Contributor

@donBarbosdonBarbos commentedMar 4, 2025
edited
Loading

I got next output for use case from issue:

Foo.__int__() must return an int, not NoneTypeFoo.__float__() must return a float, not NoneTypeFoo.__bytes__() must return a bytes, not NoneTypeFoo.__complex__() must return a complex, not NoneTypeFoo.__bool__() must return a bool, not NoneTypeFoo.__str__() must return a str, not NoneType

but we still have a lot of other places where wrong type errors have inconsistent messages. should they be updated too?

Copy link
Contributor

@jstasiakjstasiak left a comment

Choose a reason for hiding this comment

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

Drive-by comment: does it make sense to have tests for these changes?

@donBarbos
Copy link
ContributorAuthor

Drive-by comment: does it make sense to have tests for these changes?

it seems that we don't check the text of error messages if we don't want to check the error type itself

Copy link
Member

@JelleZijlstraJelleZijlstra left a comment

Choose a reason for hiding this comment

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

I think many of the changes in wording are not clear improvements.

@@ -1421,17 +1423,17 @@ _PyNumber_Index(PyObject *item)

if (!PyLong_Check(result)) {
PyErr_Format(PyExc_TypeError,
"__index__ returned non-int (type %.200s)",

Choose a reason for hiding this comment

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

I don't see much reason to change this error message either.

Copy link
ContributorAuthor

@donBarbosdonBarbosApr 29, 2025
edited
Loading

Choose a reason for hiding this comment

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

I changed it to the more common way as you recommended elsewhere:__method__() must return an int, not ...
and added type info before method name, like for other methods

@@ -2435,10 +2436,8 @@ method_output_as_list(PyObject *o, PyObject *meth)
PyThreadState *tstate = _PyThreadState_GET();
if (_PyErr_ExceptionMatches(tstate, PyExc_TypeError)) {
_PyErr_Format(tstate, PyExc_TypeError,
"%.200s.%U() returned a non-iterable (type %.200s)",

Choose a reason for hiding this comment

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

Here I strongly prefer the old message. Iterable is not a type, it's a category of types.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

what do you think about new message:"%T.%U() must return an iterable, not %T"

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jstasiakjstasiakjstasiak left review comments

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

@ericsnowcurrentlyericsnowcurrentlyAwaiting requested review from ericsnowcurrentlyericsnowcurrently is a code owner

@skirpichevskirpichevAwaiting requested review from skirpichev

@JelleZijlstraJelleZijlstraAwaiting requested review from JelleZijlstraJelleZijlstra is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@donBarbos@jstasiak@JelleZijlstra@skirpichev

[8]ページ先頭

©2009-2025 Movatter.jp