-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Should __rpow__()
take modulo
argument?
#122193
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
Comments
I don't think so. |
Docs says: "Note that ternary pow() will not try calling __rpow__() (the coercion rules would become too complicated)." Probably, this is not something, that might be changed (see recent discussion in https://discuss.python.org/t/35185). Lets simplify signature of this dunder method.
Third-party arithmetic libraries are free to implement the complicated coercion rules (or simplify them for their use case), and call And anyone who implements |
@encukou, not sure I get your point.
Of course, they are free to do such (strange) things too. But that means they can't use python's arithmetic operators and builtin functions, e.g.
Using Python dunder methods in such a library will be only a source of confusion. I would count such cases as library bugs. On another hand, coercion rules for ternary ops in the CPython could be treated as an implementation details (and that should be clearly stated in docs). Different implementations may take other decisions here. Sorry, but I doubt that this case does make sense. |
CC @picnixz It seems, three-arg form |
At the time when I reacted with a 👍, I think this is what I had in mind.
Yes and no I think. My reasoning was sa follows: it's possible to have some dispatcher mechanism, say class Interface:
def rpow(self, x, mod=None):
# pre-validation of rpow()
# then call the "fast" implementation directly.
return self.__rpow__(x, mod)
def __rpow__(self, x, mod=None):
# actual implementation of rpow()
... From a design PoV, this could make sense to some users, where the dunder is the "fast & protected implementation, no redundant checks" while "rpow()" is the public method. So, even it our built-ins would never call I also think it's fine to keep identical input arguments for I think I mainly reacted 👍 to indicate that it's fine to keep a general form even though we don't use it ourselves. |
This doesn't explain why someone will use poor dispatching mechanism, coming from Python, instead of proper multiple dispatch. And I guess nobody know real-world examples of this.
On another hand it's more difficult to remember semantics of |
closing in favor of #130104 |
Uh oh!
There was an error while loading. Please reload this page.
Documentation
The documentation for
__rpow__()
clearly states:As far as I'm aware (I may be wrong!) ternary
pow()
is the only way that themodulo
parameter can be passed to__pow__()
. Since the documentation explicitly states that ternarypow()
will not fall back on__rpow__()
, it seems misleading that the summary for__rpow__()
above contains the same optionalmodulo
parameter as for__pow__()
.Should the
modulo
parameter for__rpow__()
be removed? Or are there some means other than ternarypow()
by which this parameter can end up being passed to__rpow__()
?Linked PRs
The text was updated successfully, but these errors were encountered: