Skip to content
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-67790: Add integer-style formatting for fractions.Fraction #2

Closed
wants to merge 2 commits into from

Conversation

mdickinson
Copy link
Owner

@mdickinson mdickinson commented Jan 22, 2023

This is a proof-of-concept PR that extends python#100161 to add support for the 'd' presentation type in fractions.Fraction.__format__.

Detailed changes

  • Add 'd' presentation type, supporting alignment, fill, sign and minimum width in the obvious-ish way (minimum width applies to the whole formatted number).
  • Add support for # alternate formatting, which always includes a slash and denominator (by default, if the denominator is 1 then the slash and denominator are left out).
  • Include support for thousands separators, with the separator applied to both numerator and denominator separately.
  • Do not support zero padding, since it's not clear exactly how that would work or what the use-cases are.
  • Make 'd' the default presentation type: a missing presentation type behaves identically to 'd'.

Feature complete and tested, but not yet ready to merge - it still needs doc updates.

To do

@mdickinson
Copy link
Owner Author

(Not very) wild idea: we could add a new alignment type / that aligns fractions at the slash (to the extent possible within the given minimum width).

@mdickinson mdickinson changed the base branch from fraction-format to main October 25, 2023 10:15
@mdickinson mdickinson changed the title Add d presentation-type formatting for fractions.Fraction gh-67790: Add integer-style formatting for fractions.Fraction Oct 25, 2023
@mdickinson mdickinson force-pushed the fraction-format-d-presentation-type branch from 3b65369 to 130c717 Compare October 25, 2023 10:48
@mdickinson mdickinson closed this Oct 25, 2023
@mdickinson
Copy link
Owner Author

Re-opened as python#111320

@mdickinson
Copy link
Owner Author

we could add a new alignment type / that aligns fractions at the slash

Not doing this - no-one has asked for it, and there are some details that are unclear (like where the sign should go).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant