Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
gh-119594: Improve pow(fraction.Fraction(), b, modulo) error message#119593
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Fraction.__pow__ should act same asfloat.__pow__. This new code does not.pow(3.0, 4, 5) andpow(3.5, 4, 5)` raise "TypeError: pow() 3rd argument not allowed unless all arguments are integers" Put following at top of code:
if mod is not None: raise TypeError("pow() 3rd argument not allowed unless all arguments are integers")and correct the new test.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase And if you don't make the requested changes, you will be poked with soft cushions! |
Slight modification to Terry's suggestion: I think we can do: ifmodisnotNone:returnNotImplemented and then the general machinery should construct a reasonable error message for us. And intheory this gives other classes a chance to participate where |
wimglenn commentedMay 27, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I have made the requested changes; please review again. Should edit: Found a sort-of answer in thedocs, where it says
The ternary coercion rules inPEP 208 do seem complicated. So according to the status quo, seems a third argument for |
Thanks for making the requested changes! @terryjreedy: please review the changes made to this pull request. |
Agreed, I think. I don't think it would be activelywrong to add the check to |
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Should not__rpow__ be modified too?
mdickinson commentedMay 28, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The conclusion that@wimglenn came to in the comments above (and that I think I agree with) is that |
Ah, sorry, I did not read the discussion before looking at the code in this PR. I experimented and was not able to trigger calling |
Yep, same here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM!
@terryjreedy Okay to merge?
I am changing title and blurb to reflect user visible effect of change. Will then merge. |
Misc/NEWS.d/next/Library/2024-05-26-22-22-51.gh-issue-119594.fnQNM8.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
…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.
Fraction.__pow__does not accept the third argument whichpowtries 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? But accept the argument, and then print a better error message if modulo is not None?
Maybe it is worth adding tests for all the possible coercions too (ref:https://peps.python.org/pep-0208/)