Skip to content
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

gh-123446: Fix empty function names in TypeErrors in typeobject #123470

Merged
merged 4 commits into from
Aug 30, 2024

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Aug 29, 2024

The second option was to convert these functions to use check_num_args(args, ...), but this feels like a simplier solution.

After:

>>> str.join.__get__()
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    str.join.__get__()
    ~~~~~~~~~~~~~~~~^^
TypeError: __get__ expected at least 1 argument, got 0

Objects/typeobject.c Outdated Show resolved Hide resolved
Objects/typeobject.c Outdated Show resolved Hide resolved
@sobolevn
Copy link
Member Author

sobolevn commented Aug 29, 2024

After the last change:

>>> int().__pow__()
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    int().__pow__()
    ~~~~~~~~~~~~~^^
TypeError: expected 1 or 2 arguments, got 0
>>> int().__mul__()
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    int().__mul__()
    ~~~~~~~~~~~~~^^
TypeError: expected 1 argument, got 0
>>> int().__rmul__()
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    int().__rmul__()
    ~~~~~~~~~~~~~~^^
TypeError: expected 1 argument, got 0

Do I need to test this? Seems rather small, but in a very critical part 🤔

Objects/typeobject.c Outdated Show resolved Hide resolved
Objects/typeobject.c Show resolved Hide resolved
Objects/typeobject.c Outdated Show resolved Hide resolved
Objects/typeobject.c Show resolved Hide resolved
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM.

Comment on lines +8805 to +8811
if (size == -1) {
return NULL;
}
other = PyTuple_GET_ITEM(args, 0);
if (size == 2) {
third = PyTuple_GET_ITEM(args, 1);
}
Copy link
Member

Choose a reason for hiding this comment

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

This could also be moved into check_pow_args (or rather unpack_pow_args).

BTW, it is still a question whether __rpow__ and __ipow__ should support the third argument. Normally they never called with three arguments. So it may be better to leave the current PR code, it will be easier to change in future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we can open a new issue about that. For now, we only change the error message, not any logical parts. Thanks a lot for the review! 👍

@sobolevn sobolevn merged commit f8a736b into python:main Aug 30, 2024
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants