◐ Shell
reader mode source ↗
Skip to content

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

@serhiy-storchaka serhiy-storchaka commented Jun 21, 2021

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.
@github-actions

Copy link
Copy Markdown

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

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

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?

@serhiy-storchaka

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.

@skirpichev

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?

@serhiy-storchaka

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?

@skirpichev

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

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 iritkatriel added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Nov 28, 2023

@mdickinson 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.

Hide comment

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

Thank you!

@serhiy-storchaka serhiy-storchaka enabled auto-merge (squash) July 15, 2024 15:44
@serhiy-storchaka 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 serhiy-storchaka deleted the float-from-number branch October 21, 2024 13:43
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