-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
gh-84978: Add float.from_number() and complex.from_number() #26827
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
f3e83a4
Compare
This PR is stale because it has been open for 30 days with no activity. |
@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? |
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? |
@serhiy-storchaka, some tests refactoring in test_float/complex is irrelevant for this pr. Can I port this as a separate pr? |
This tests refactoring in test_float/complex is required for testing |
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. |
@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 <[email protected]>
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 LGTM, and works as expected in my manual testing. I only have a couple of grammar nitpicks.
Thank you!
@@ -624,6 +624,23 @@ Additional Methods on Float | |||
The float type implements the :class:`numbers.Real` :term:`abstract base | |||
class`. float also has the following additional methods. | |||
|
|||
.. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Co-authored-by: Mark Dickinson <[email protected]>
…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