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: Do not ignore the third argument in slot_nb_inplace_power() #130225

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

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Feb 17, 2025

The default implementation of the nb_inplace_power slot no longer ignores the third argument, but passes it to the __ipow__ method if its value is not None.

…ower()

The default implementation of the nb_inplace_power slot no longer
ignores the third argument, but passes it to the __ipow__ method
if its value is not None.
Copy link
Member

@skirpichev skirpichev left a comment

Choose a reason for hiding this comment

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

This looks fine from the technical side, but I'm not sure if this is a good idea.

  1. Apparently, this 3-arg form isn't used somewhere for years.
  2. There is no way to invoke this from pure-Python. Do we have some in-place shortcut for this stuff in some other language?
  3. PyNumber_InPlacePower() still wrong: "The operation is done in-place when o1 supports it. This is the equivalent of the Python statement o1 **= o2 when o3 is Py_None, or an in-place variant of pow(o1, o2, o3) otherwise." There is no in-place variant of pow().

IMO, better to drop the module argument from __ipow__().

@serhiy-storchaka
Copy link
Member Author

There is no in-place variant of pow().

Yes, this is hypothetical in-place variant of pow(). If there was some function, it would be used in the documentation.

The current behavior is inconsistent. If __ipow__ is not defined, then the third argument is not ignored, but passed to __pow__. If __ipow__ is defined, then the third argument is ignored. For extension classes it is not ignored, it is only ignored for Python classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants