Issue38302
➜
This issue tracker will soon become read-only and move to GitHub.
For a smoother transition, remember to
log in and link your GitHub username to your profile.
For more information,
see this post about the migration.
Created on 2019-09-27 21:55 by DeepSpace, last changed 2021-02-26 19:59 by brett.cannon. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 16459 | merged | ashkop, 2019-09-28 11:57 | |
| PR 24587 | closed | brett.cannon, 2021-02-19 23:25 | |
| Messages (10) | |||
|---|---|---|---|
| msg353419 - (view) | Author: Adi (DeepSpace) | Date: 2019-09-27 21:55 | |
Due to shared code between the 2 and 3 forms of pow, the following code causes a TypeError:
class A:
def __init__(self, val):
self.val = val
def __ipow__(self, other):
return NotImplemented
class B:
def __init__(self, val):
self.val = val
def __rpow__(self, other):
return A(other.val ** self.val)
a = A(2)
b = B(2)
a **= b
(https://stackoverflow.com/questions/58141475/ipow-raising-typeerror-when-left-hand-side-object-returns-notimplemented)
|
|||
| msg353422 - (view) | Author: Adi (DeepSpace) | Date: 2019-09-27 22:00 | |
Meant to say "... 2 and 3 arguments forms of pow, ..." |
|||
| msg353503 - (view) | Author: hongweipeng (hongweipeng) * | Date: 2019-09-29 16:13 | |
The document says(https://docs.python.org/3.9/reference/datamodel.html?highlight=__rpow__#object.__rpow__): >Note that ternary pow() will not try calling __rpow__() (the coercion rules would become too complicated). |
|||
| msg353505 - (view) | Author: Ammar Askar (ammar2) * ![]() |
Date: 2019-09-29 16:55 | |
This isn't the ternary form of pow(), the documentation there is referring to the `pow(base, exp, modulus)`. |
|||
| msg353595 - (view) | Author: hongweipeng (hongweipeng) * | Date: 2019-09-30 16:51 | |
Oh, I see. Thank you. |
|||
| msg375825 - (view) | Author: Brett Cannon (brett.cannon) * ![]() |
Date: 2020-08-23 19:37 | |
It turns out **= ONLY calls __ipow__ and neither __pow__ or __rpow__ as the data model says should be called. - Data Model: https://docs.python.org/3/reference/datamodel.html#object.__ipow__ - PyNumber_InPlacePower(): https://github.com/python/cpython/blob/802726acf6048338394a6a4750835c2cdd6a947b/Objects/abstract.c#L1159 - ternary_op (which is what is used to implement PyNumber_InPlacePower(): https://github.com/python/cpython/blob/802726acf6048338394a6a4750835c2cdd6a947b/Objects/abstract.c#L849 |
|||
| msg376208 - (view) | Author: Brett Cannon (brett.cannon) * ![]() |
Date: 2020-09-01 20:09 | |
I have opened https://bugs.python.org/issue41688 to track the documentation fixes so that this can become a release blocker for Python 3.10. |
|||
| msg386108 - (view) | Author: Pablo Galindo Salgado (pablogsal) * ![]() |
Date: 2021-02-01 20:50 | |
Friendly reminder that this issue is currently blocking the 3.10a5 release. If you are ok with waiting for the next release to include the fix, please say so here or drop me an email/ |
|||
| msg386124 - (view) | Author: Brett Cannon (brett.cannon) * ![]() |
Date: 2021-02-02 00:30 | |
I'm totally fine with pushing this until b1 since this has been broken for ages. |
|||
| msg387741 - (view) | Author: Brett Cannon (brett.cannon) * ![]() |
Date: 2021-02-26 19:58 | |
New changeset cc02b4f2e810ab524d845daa18bc94df5b092dd8 by Alex in branch 'master': bpo-38302: __pow__/__rpow__ now called when __ipow__ returns NotImplemented (#16459) https://github.com/python/cpython/commit/cc02b4f2e810ab524d845daa18bc94df5b092dd8 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2021-02-26 19:59:01 | brett.cannon | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2021-02-26 19:58:49 | brett.cannon | set | messages: + msg387741 |
| 2021-02-19 23:25:31 | brett.cannon | set | pull_requests: + pull_request23367 |
| 2021-02-02 00:30:52 | brett.cannon | set | messages: + msg386124 |
| 2021-02-01 20:50:33 | pablogsal | set | nosy:
+ pablogsal messages: + msg386108 |
| 2020-10-04 16:24:13 | lukasz.langa | set | title: __pow__ and __rpow__ are not reached when __ipow__ returns NotImplemented for **= -> [3.10] __pow__ and __rpow__ are not reached when __ipow__ returns NotImplemented for **= |
| 2020-09-01 20:09:07 | brett.cannon | set | priority: high -> release blocker messages:
+ msg376208 |
| 2020-08-23 19:37:28 | brett.cannon | set | priority: normal -> high title: __rpow__ not reached when __ipow__ returns NotImplemented -> __pow__ and __rpow__ are not reached when __ipow__ returns NotImplemented for **= nosy: + brett.cannon messages: + msg375825 versions: + Python 3.8, Python 3.9, Python 3.10, - Python 3.6, Python 3.7 |
| 2019-09-30 16:51:08 | hongweipeng | set | messages: + msg353595 |
| 2019-09-29 16:55:33 | ammar2 | set | nosy:
+ ammar2 messages: + msg353505 |
| 2019-09-29 16:13:12 | hongweipeng | set | nosy:
+ hongweipeng messages: + msg353503 |
| 2019-09-28 11:57:01 | ashkop | set | keywords:
+ patch stage: patch review pull_requests: + pull_request16041 |
| 2019-09-28 07:27:18 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka |
| 2019-09-27 22:00:16 | DeepSpace | set | messages: + msg353422 |
| 2019-09-27 21:58:57 | DeepSpace | set | type: behavior |
| 2019-09-27 21:55:15 | DeepSpace | create | |
