Open Cartroo opened 3 months ago
Or are there some means other than ternary pow() by which this parameter can end up being passed to rpow()?
I don't think so.
Third-party arithmetic libraries are free to implement the complicated coercion rules (or simplify them for their use case), and call __rpow__
directly.
And anyone who implements __rpow__
is free to raise an error if the third argument is unimplemented or doesn't make sense.
@encukou, not sure I get your point.
Third-party arithmetic libraries are free to implement the complicated coercion rules (or simplify them for their use case), and call
__rpow__
directly.
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. **
or pow()
.
And anyone who implements
__rpow__
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.
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