Uh oh!
There was an error while loading. Please reload this page.
gh-84978: Add float.from_number() and complex.from_number() - #26827
Conversation
They are alternate constructors which only accept numbers (including objects with special methods __float__, __complex__ and __index__), but not strings.
d54d0ef to
f3e83a4CompareThis PR is stale because it has been open for 30 days with no activity. |
mdickinson
commented
Sep 4, 2022
@serhiy-storchaka Are you still interested in pursuing this? Looks like it's still a draft; what's needed to make it ready for review? |
serhiy-storchaka
commented
Sep 4, 2022
It needs documentation. I'll write it if the rest be set. It differs from your original idea (class methods instead of Should we add also special constructors for parsing? |
skirpichev
commented
Oct 6, 2023
@serhiy-storchaka, some tests refactoring in test_float/complex is irrelevant for this pr. Can I port this as a separate pr? |
serhiy-storchaka
commented
Oct 6, 2023
This tests refactoring in test_float/complex is required for testing |
skirpichev
commented
Oct 6, 2023
I was thinking about similar refactoring while improving test coverage for the complexobject.c. So, maybe this could be useful regardless of the fate of this pr. |
serhiy-storchaka
commented
Oct 15, 2023
@mdickinson I added docs and remove the draft status. Hope it will help with review. |
Taken from python#26827 Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
mdickinson
left a comment
There was a problem hiding this comment.
This LGTM, and works as expected in my manual testing. I only have a couple of grammar nitpicks.
Thank you!
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| .. classmethod:: float.from_number(x) | ||
| Class method to return a floating point number constructed from a number *x*. |
There was a problem hiding this comment.
Super-nitpick: I prefer the spelling floating-point number, with a hyphen (the "floating-point" part acts as a compound adjective). I think that's what we mostly use throughout the docs (though no doubt there are exceptions).
There was a problem hiding this comment.
This descriptions was simply copied from the float constructor description.
"floating-point" occurs 118 time, "floating point" occurs at least 159 times (in several cases it is split between lines, so it is not easy to get accurate number).
So for now I leave "floating point" for consistency with the constructor description. We will solve this in a separate issue.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
…thonGH-26827) They are alternate constructors which only accept numbers (including objects with special methods __float__, __complex__ and __index__), but not strings.
They are alternate constructors which only accept numbers
(including objects with special methods
__float__,__complex__and
__index__), but not strings.https://bugs.python.org/issue40801