-
-
Notifications
You must be signed in to change notification settings - Fork 33k
bpo-44115: improve duck-typing of fractions #26064
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
Conversation
allow any object that has an as_integer_ratio method to be converted to fractions. This is helpful especially for numpy types, which have said method but do not inherit from the classes that can currently be converted to fractions.
Misc/NEWS.d/next/Library/2021-05-12-13-18-28.bpo-44115.Y11_u8.rst
Outdated
Show resolved
Hide resolved
|
Even though I like the idea I see a problem with relying on Also, I don't see too much overhead in converting those objects to |
|
Well, whether we rely on the method by the same name doing the same thing is mostly a philosophical question. Traditionally, in the Python community, the response was clear: if it quacks like a duck, it is a duck. Just converting to float is simply not an option: fractions simply are much more precise than floats, as in exact. If you convert 1/3 to floats, you lose precision. Same happens for converting Decimals, or numpy's float128. |
|
This all looks good. Please update the docs as well (including a versionchanged note). |
|
After reading a lot on this topic on bpo, I realized that it could be a good idea to simply add How do you like it? |
|
This PR is stale because it has been open for 30 days with no activity. |
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.
Looks ok
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.
This PR has merge conflicts now.
|
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 |
|
Accepting any object with |
allow any object that has an as_integer_ratio method to be
converted to fractions.
This is helpful especially for numpy types, which have said method
but do not inherit from the classes that can currently be converted
to fractions.
https://bugs.python.org/issue44115