[New-bugs-announce] [issue41903] PyNumber_InPlacePower ignores o3 if o1 implements __ipow__
Simon Cross
report at bugs.python.org
Thu Oct 1 11:10:02 EDT 2020
New submission from Simon Cross <hodgestar at gmail.com>:
The documentation for PyNumber_InPlacePower [1] reads:
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. If o3 is to be ignored, pass Py_None in its place (passing NULL for o3 would cause an illegal memory access).
However, if a class A implements __ipow__ then PyNumber_InPlacePower(o1, o2, o3) ALWAYS ignores o3 if o1 is an instance of A.
This happens because if A implements __ipow__ then PyNumber_InPlacePower always calls the nb_inplace_power slot [2] and the slot always drops the third argument [3].
This appears to have always been the case in Python, so likely a small documentation patch is all that is required. If people agree, I will open a documentation pull request.
[1] https://docs.python.org/3/c-api/number.html?highlight=pynumber_inplacepower#c.PyNumber_InPlacePower
[2] https://github.com/python/cpython/blob/master/Objects/abstract.c#L1164
[3] https://github.com/python/cpython/blob/master/Objects/typeobject.c#L6631-L6636
----------
components: C API
messages: 377758
nosy: hodgestar
priority: normal
severity: normal
status: open
title: PyNumber_InPlacePower ignores o3 if o1 implements __ipow__
type: behavior
versions: Python 3.10, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41903>
_______________________________________
More information about the New-bugs-announce
mailing list