Skip to content

Conversation

@skirpichev
Copy link
Contributor

@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
Contributor 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
Contributor 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
Contributor 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
Contributor 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).

@skirpichev skirpichev closed this Sep 9, 2025
@skirpichev skirpichev deleted the correct-__ipow__-signature/86069 branch September 9, 2025 04:49
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