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-86069: correct object.__ipow__() signature #130103

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

skirpichev
Copy link
Member

@skirpichev skirpichev commented Feb 14, 2025

There is no way to call ternary form of this dunder.


📚 Documentation preview 📚: https://cpython-previews--130103.org.readthedocs.build/

There is no way to call ternary form of this dunder.
@skirpichev
Copy link
Member Author

See

cpython/Objects/typeobject.c

Lines 9905 to 9911 in 28f5e3d

/* Can't use SLOT1 here, because nb_inplace_power is ternary */
static PyObject *
slot_nb_inplace_power(PyObject *self, PyObject * arg1, PyObject *arg2)
{
PyObject *stack[2] = {self, arg1};
return vectorcall_method(&_Py_ID(__ipow__), stack, 2);
}

So, PyNumber_InPlacePower just ignores the o3 now. Maybe its docs also should be adjusted?

Copy link

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

this seems to be correct change.

@serhiy-storchaka
Copy link
Member

Look at wrap_ternaryfunc(). The __ipow__ wrapper accepts 1 or 2 positional arguments (not including self). An extension type can implement slot_nb_inplace_power that does not ignore the third argument.

@skirpichev
Copy link
Member Author

An extension type can implement slot_nb_inplace_power that does not ignore the third argument.

How you can invoke it? (excluding a direct call of the dunder)

@serhiy-storchaka
Copy link
Member

By a direct call of __ipow__().

@skirpichev
Copy link
Member Author

"excluding a direct call of the dunder"?)

@serhiy-storchaka
Copy link
Member

Don't exclude it. Signature describes the direct call.

@skirpichev
Copy link
Member Author

skirpichev commented Feb 14, 2025

Well, why someone will prefer a dunder method over a public method, that does same?)

Edit: similar to #122260 (3-arg __rpow__() - also expected to be directly called).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review docs Documentation in the Doc dir skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

3 participants