8000 bpo-39096: Improve description of 'e', 'f' and 'g' presentation types by mdickinson · Pull Request #23537 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-39096: Improve description of 'e', 'f' and 'g' presentation types #23537

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

Conversation

mdickinson
Copy link
Member
@mdickinson mdickinson commented Nov 28, 2020

The table of presentation types in the "Format specification mini-language" section of the library documentation tries to cover both Decimal and float, but is inaccurate in a number of ways for Decimal.

This PR fixes one particular part of that inaccuracy - the description of the default precision - and makes some other cleanups and consistency fixes along the way. In more detail:

  • Replace the verbs "prints" and "displays" with "formats".
  • Replace "Exponent notation" with "Scientific E notation", which appears to be closer to the proper term.

I'm aiming for an incremental improvement here rather than a complete, perfectly-accurate description.

A wider issue is whether we should be attempting to document the rules for Decimal at all in this table, or whether we should simply document these as the rules for float, and move the description for Decimal elsewhere. But I think that ship has sailed already.

@ericvsmith : Any interest in reviewing?

https://bugs.python.org/issue39096

Copy link
Member
@ericvsmith ericvsmith left a comment

Choose a reason for hiding this comment

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

This looks great, @mdickinson. I just have a few small comments, feel free to ignore them.

| | precision given, uses a precision of ``6`` digits after |
| | the decimal point for :class:`float`, and uses a |
| | precision large enough to show all coefficient digits |
| | for :class:`~decimal.Decimal`. |
Copy link
Member

Choose a reason for hiding this comment

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

Same comment about p == 0 and omitting the decimal point.

| | significant digits. With no precision given, uses a |
| | precision of ``6`` digits after the decimal point for |
| | :class:`float`, and shows all coefficient digits |
| | for :class:`~decimal.Decimal`. |
Copy link
Member

Choose a reason for hiding this comment

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

Should you mention here that if p == 0, the decimal point is omitted unless # is used?

Also: is it generally understood that for Decimal, "all coefficient digits" includes the trailing zeros? Again, I can see people reporting it as an issue until they're told that the trailing zeros are significant.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, my original draft for this text had an "(including trailing zeros)"; I can put it back. I took it out partly because the text seemed to be getting too long, and partly out of a fear that it might cause more confusion rather than less and lead to a need to explain exactly what's meant by "trailing zeros". And this doesn't seem like the right place for that explanation.

So ... not sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

And yes, I'll update for the missing decimal point, both here and for the f text.

Copy link
Member

Choose a reason for hiding this comment

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

You're probably right about leaving out the "trailing zeros". There's a lot here already.

Copy link
Member Author

Choose a reason for hiding this comment

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

if p == 0, the decimal point is omitted unless # is used

Argh. The reality is messy. Decimal apparently still doesn't support the # alternate format. (There ought to be an issue open about this somewhere.)

There's a paragraph below the table about the inclusion or not of the decimal point. I'll see if I can update that to reflect reality.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mdickinson
Copy link
Member Author

Updated for review comments. The table still leaves it unclear that the alternate form is not supported for Decimal.

Copy link
Member
@ericvsmith ericvsmith left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks for your work on this.

It would probably be easier to add # support for Decimal that try to shoe horn the lack thereof into this table!

@mdickinson mdickinson merged commit c642374 into python:master Nov 29, 2020
@bedevere-bot
Copy link

@mdickinson: Please replace # with GH- in the commit message next time. Thanks!

@miss-islington
Copy link
Contributor

Thanks @mdickinson for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8, 3.9.
🐍🍒⛏🤖

@mdickinson mdickinson deleted the doc/fix-mini-language-descriptions-for-decimal branch November 29, 2020 09:34
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 29, 2020
…pythonGH-23537)

* Improve description of 'e', 'f' and 'g' presentation types

* Drop the 'E' from Scientific 'E' notation; remove >= 0 qualifications

* Fix false statement that the alternate form is valid for Decimal

* Nitpick: remove the Harvard/Oxford comma

* Add note that the decimal point is also removed if no digits follow it, except in alternate form
(cherry picked from commit c642374)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Nov 29, 2020
@bedevere-bot
Copy link

GH-23550 is a backport of this pull request to the 3.9 branch.

@mdickinson mdickinson restored the doc/fix-mini-language-descriptions-for-decimal branch November 29, 2020 09:35
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 29, 2020
…pythonGH-23537)

* Improve description of 'e', 'f' and 'g' presentation types

* Drop the 'E' from Scientific 'E' notation; remove >= 0 qualifications

* Fix false statement that the alternate form is valid for Decimal

* Nitpick: remove the Harvard/Oxford comma

* Add note that the decimal point is also removed if no digits follow it, except in alternate form
(cherry picked from commit c642374)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
@bedevere-bot
Copy link

GH-23551 is a backport of this pull request to the 3.8 branch.

@mdickinson mdickinson deleted the doc/fix-mini-language-descriptions-for-decimal branch November 29, 2020 09:35
@mdickinson mdickinson restored the doc/fix-mini-language-descriptions-for-decimal branch November 29, 2020 09:35
mdickinson added a commit that referenced this pull request Nov 29, 2020
…GH-23537) (GH-23550)

* Improve description of 'e', 'f' and 'g' presentation types

* Drop the 'E' from Scientific 'E' notation; remove >= 0 qualifications

* Fix false statement that the alternate form is valid for Decimal

* Nitpick: remove the Harvard/Oxford comma

* Add note that the decimal point is also removed if no digits follow it, except in alternate form
(cherry picked from commit c642374)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
mdickinson added a commit that referenced this pull request Nov 29, 2020
…GH-23537) (GH-23551)

* Improve description of 'e', 'f' and 'g' presentation types

* Drop the 'E' from Scientific 'E' notation; remove >= 0 qualifications

* Fix false statement that the alternate form is valid for Decimal

* Nitpick: remove the Harvard/Oxford comma

* Add note that the decimal point is also removed if no digits follow it, except in alternate form
(cherry picked from commit c642374)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
…python#23537)

* Improve description of 'e', 'f' and 'g' presentation types

* Drop the 'E' from Scientific 'E' notation; remove >= 0 qualifications

* Fix false statement that the alternate form is valid for Decimal

* Nitpick: remove the Harvard/Oxford comma

* Add note that the decimal point is also removed if no digits follow it, except in alternate form
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0