FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-84978: Add float.from_number() and complex.from_number() by serhiy-storchaka · Pull Request #26827 · python/cpython · GitHub

/ cpython Public

gh-84978: Add float.from_number() and complex.from_number() - #26827

Merged
serhiy-storchaka merged 9 commits into
python:mainfrom
serhiy-storchaka:float-from-number
Jul 15, 2024
Merged

gh-84978: Add float.from_number() and complex.from_number()#26827
serhiy-storchaka merged 9 commits into
python:mainfrom
serhiy-storchaka:float-from-number

Conversation

serhiy-storchaka commented Jun 21, 2021
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

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

They are alternate constructors which only accept numbers
(including objects with special methods __float__, __complex__
and __index__), but not strings.

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

github-actions Bot added the stale Stale PR or inactive for long period of time. label Jul 22, 2021
github-actions Bot removed the stale Stale PR or inactive for long period of time. label Aug 10, 2022

Copy link
Copy Markdown
Member

@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?

Copy link
Copy Markdown
Member Author

It needs documentation. I'll write it if the rest be set.

It differs from your original idea (class methods instead of operator functions), so I do not know what you think about this. The spelling is also can be discussed (from_number vs fromnumber, or maybe something other?) Should int.from_number be added?

Should we add also special constructors for parsing? int.parse or int.from_string, etc. It can be done in a different PR, but it is useful to keep it in mind.

Copy link
Copy Markdown
Member

@serhiy-storchaka, some tests refactoring in test_float/complex is irrelevant for this pr. Can I port this as a separate pr?

Copy link
Copy Markdown
Member Author

This tests refactoring in test_float/complex is required for testing from_number() methods. Without it they are irrelevant. Why do you need this?

Copy link
Copy Markdown
Member

Why do you need this?

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 marked this pull request as ready for review October 14, 2023 20:10
serhiy-storchaka changed the title bpo-40801: Add float.from_number() and complex.from_number() gh-84978: Add float.from_number() and complex.from_number() Oct 14, 2023

Copy link
Copy Markdown
Member Author

@mdickinson I added docs and remove the draft status. Hope it will help with review.

skirpichev added a commit to skirpichev/cpython that referenced this pull request Oct 17, 2023
Taken from python#26827

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
iritkatriel added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Nov 28, 2023

mdickinson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This LGTM, and works as expected in my manual testing. I only have a couple of grammar nitpicks.

Thank you!

Comment thread Doc/library/functions.rst Outdated
Comment thread Doc/library/functions.rst Outdated
Comment thread Doc/library/stdtypes.rst

.. classmethod:: float.from_number(x)

Class method to return a floating point number constructed from a number *x*.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Comment thread Doc/whatsnew/3.13.rst Outdated
serhiy-storchaka enabled auto-merge (squash) July 15, 2024 15:44
serhiy-storchaka merged commit 94bee45 into python:main Jul 15, 2024
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
…thonGH-26827)

They are alternate constructors which only accept numbers
(including objects with special methods __float__, __complex__
and __index__), but not strings.
serhiy-storchaka deleted the float-from-number branch October 21, 2024 13:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

interpreter-core (Objects, Python, Grammar, and Parser dirs)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL