Uh oh!
There was an error while loading. Please reload this page.
bpo-45995: add "z" format specifer to coerce negative 0 to zero - #30049
Conversation
97a033b to
8ff811fCompareThere was a problem hiding this comment.
if PR #29438 lands, then detection of the "z" option can be incorporated into our forked mpd_parse_fmt_str_ex(), rather than this preprocessing of the format string
There was a problem hiding this comment.
I think it's the case that one way or the other, the format spec is going to need to be completely parsed to figure out if a given 'z' is used for no_neg_0.
Uh oh!
There was an error while loading. Please reload this page.
This PR is stale because it has been open for 30 days with no activity. |
mdickinson
commented
Jan 22, 2022
Removing the stale label; discussion is ongoing on the bug tracker. |
1bfb289 to
bb4d5f1Comparemdickinson
commented
Mar 6, 2022
Update: the PEP has been accepted - https://discuss.python.org/t/accepting-pep-682-format-specifier-for-signed-zero/14088 We should aim to get this reviewed and in by the next (and final) alpha release of 3.11, due April 5th. |
mdickinson
left a comment
There was a problem hiding this comment.
Hi @belm0. Here's a first-pass review; apologies for taking so long to get to this.
Most of the comments are nitpick-level. The big exception is the Decimal code, where I think there's still significant work to do.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
bedevere-bot
commented
Mar 13, 2022
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
mdickinson
commented
Mar 13, 2022
@ericvsmith: if you have any bandwidth to look over the code at some point before the first 3.11 beta, I'd appreciate your input. |
Uh oh!
There was an error while loading. Please reload this page.
belm0
left a comment
There was a problem hiding this comment.
Thank you for the thorough review!
I'm bogged down a bit and it may take a week or so to reconcile the comments.
Hoping to get this merged for the next (final) alpha.
3.11.0 alpha 7: Tuesday, 2022-04-05
3.11.0 beta 1: Friday, 2022-05-06
Uh oh!
There was an error while loading. Please reload this page.
This covers str.format() and f-strings. Old-style string interpolation is not supported. TODO: Decimal support
| if (no_neg_0 && mpd_isnegative(mpd) && !mpd_isspecial(mpd)) { | ||
| /* Round into a temporary (carefully mirroring the rounding | ||
| of mpd_qformat_spec()), and check if the result is negative zero. | ||
| If so, clear the sign and format the resulting positive zero. */ |
There was a problem hiding this comment.
An insight I had recently was that, once negative zero is confirmed somehow, producing the correct output is only a matter of formatting positive zero (which cannot be affected by directed rounding, etc.).
As for how to detect negative zero, the options are: 1) round independently of the format function, or 2) analyze the string result of the format function (as Mark suggested). I found the former easier to manage, since it's a matter of duplicating a small amount of proven mpd library code, and is relatively straightforward to test. In contrast, analyzing the format output involves writing a new and perfectly-correct regex or parser, and imagining all the format spec edge cases to test it with.
mdickinson
left a comment
There was a problem hiding this comment.
Here's a second-pass review. We're getting there, but there are still a couple of bugs to resolve.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
mdickinson
left a comment
There was a problem hiding this comment.
Thank you for the updates! This looks ready to merge to me. I've been running some automated tests that cover a wide variety of combinations, and haven't yet managed to break this. :-)
A bit off-topic: I do think we're introducing some DRY-type technical debt into _decimal.c, though for this PR I don't see an easy alternative. For the future, there's scope for some cleanup after lifting the formatting machinery from libmpdec to _decimal.c. That's for another day, though.
Uh oh!
There was an error while loading. Please reload this page.
ericvsmith
left a comment
There was a problem hiding this comment.
Other than possibly adding a credit in the blurb, this looks good to me.
ghost
commented
Apr 11, 2022
belm0
commented
Apr 11, 2022
using file edit from the github UI appears to have angered CLA bot and bedevere |
ericvsmith
commented
Apr 11, 2022
I think it's related to the bpo to github issues migration. I'll see what I can figure out. |
mdickinson
commented
Apr 11, 2022
The "CLA Signing" check doesn't seem to be required for merging. Given that we know that CLA signing has occurred, I think we should be okay to merge. I've reported the failure to @ambv. |
The implementation of PEP 682 was completed in python/cpython#30049.
The implementation of PEP 682 was completed in python/cpython#30049.
This option coerces negative zero into zero after rounding to the format precision.
Covers formatting of standard fraction types (
float,Decimal,complex) viastr.format(), built-informat(), and f-strings. Old-style string interpolationis not supported.
https://www.python.org/dev/peps/pep-0682/
https://bugs.python.org/issue45995