-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent error messages when returning the wrong type for the type-conversion magic methods #130821
Comments
The difference is Lines 1529 to 1534 in d780f0a
vs Lines 1607 to 1612 in d780f0a
CC @serhiy-storchaka as author of 16931c3. I don't think that inconsistency is a real bug. But that does make sense for me as a feature request: i.e. include type information to the exception message. |
I've marked this as easy for anyone that wants to dive into the C code for the first time. |
if no one minds I'm going to send a PR with a unified message using as a reference message: |
but after "grep" sources i found more cases with grep output
should we add type information to other methods and to methods from modules in stdlib? |
Looks like a nice idea to me. You can use |
here are more examples of error messages:
I suggest using the following template for all of them: |
I like it. But since it's such a wide change, we need approval from more core developers. Could you open a discussion at https://discuss.python.org/? I think also that there should be parentheses after the method name. This would help to distinguish them from attributes. |
yes, i can. but should i propose in this discussion to create PEP or just propose to change error messages of the methods i have cited? EDIT: I don't mind if you open it. Maybe you know better what to use as arguments :) |
Just change the error messages. Inclusion of the type is a plus, and since we change the error messages, we can use an opportunity to unify them more. Propose several variants, add variants proposed by commenters, and open a poll. My English is poor, so I can't choose the best variant. But I support the change in general. |
Link to discuss page: https://discuss.python.org/t/error-messages-for-methods/83362 |
Bug report
Bug description:
I noticed the error messages between magic methods like
__int__
and__float__
were inconsistent. This seems like slightly undesirable behavior to me. I used the following code to generate many of them.And the output is as follows:
The first issue I've made, but seems like a reasonable bug. I'm not sure if there are other "type-conversion" magic methods out there that aren't consistent.
CPython versions tested on:
3.13, 3.12
Operating systems tested on:
Windows
Linked PRs
The text was updated successfully, but these errors were encountered: