Skip to content

gh-86069: correct object.__ipow__() signature#130103

Closed
skirpichev wants to merge 4 commits into
python:mainfrom
skirpichev:correct-__ipow__-signature/86069
Closed

gh-86069: correct object.__ipow__() signature#130103
skirpichev wants to merge 4 commits into
python:mainfrom
skirpichev:correct-__ipow__-signature/86069

Conversation

@skirpichev

@skirpichev skirpichev commented Feb 14, 2025

Copy link
Copy Markdown
Member

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
Copy Markdown
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?

@auvipy auvipy left a comment

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

By a direct call of __ipow__().

@skirpichev

Copy link
Copy Markdown
Member Author

"excluding a direct call of the dunder"?)

@serhiy-storchaka

Copy link
Copy Markdown
Member

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

@skirpichev

skirpichev commented Feb 14, 2025

Copy link
Copy Markdown
Member Author

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