-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Improve pow(fraction.Fraction(), b, modulo) error message #119594
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
Since the exception type is correct, this should be considered an enhancement rather than bug. PR was a bit premature without agreement of what fix should be. |
Not supporting a modulus was an intentional choice here. It's hard to imagine real use-cases would be for supporting the modulus. If If we want to change the error message (as @terryjreedy pointed out, the exception type is already the right one), the first thing to try would be to return |
It does. Results of a quick test: >>> pow(Fraction(2), 3)
Fraction(8, 1)
>>> pow(Fraction(2), 3, 5)
Traceback (most recent call last):
File "<python-input-4>", line 1, in <module>
pow(Fraction(2), 3, 5)
~~~^^^^^^^^^^^^^^^^^^^
TypeError: unsupported operand type(s) for ** or pow(): 'Fraction', 'int', 'int' |
…119593) If one calls pow(fractions.Fraction, x, module) with modulo not None, the error message now says that the types are incompatible rather than saying pow only takes 2 arguments. Implemented by having fractions.Fraction __pow__ accept optional modulo argument and return NotImplemented if not None. pow() then raises with appropriate message. --------- Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
…ssage (python#119593) If one calls pow(fractions.Fraction, x, module) with modulo not None, the error message now says that the types are incompatible rather than saying pow only takes 2 arguments. Implemented by having fractions.Fraction __pow__ accept optional modulo argument and return NotImplemented if not None. pow() then raises with appropriate message. --------- Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
…ssage (python#119593) If one calls pow(fractions.Fraction, x, module) with modulo not None, the error message now says that the types are incompatible rather than saying pow only takes 2 arguments. Implemented by having fractions.Fraction __pow__ accept optional modulo argument and return NotImplemented if not None. pow() then raises with appropriate message. --------- Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Bug description:
Fraction.__pow__
does not accept the third argument whichpow
tries to pass to it:Other number types don't do that, they support it when they can and print an error message if they don't want to, e.g.
I'm not sure what fraction should do, maybe it should just continue not to support it? Or just accept the argument, and then print a better error message if modulo is not None?
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: