gh-144087: Add support for unicode MINUS SIGN in `int`, `float` and `complex` by johnslavik · Pull Request #144095 · python/cpython
LGTM. Needs tests and blurb. Maybe consider making the assignment a constant instead of a comment, though I don't feel strongly about it.
I don't see a different approach to solving this that is equally or more optimal in terms of trade-offs
How about only checking for the first non whitespace character? signs should not appear in the middle of a number unless they are in the e/E/p suffix I guess?
How about only checking for the first non whitespace character?
Hardly this optimizes something.
unless they are in the e/E/p suffix I guess?
Yes. _PyUnicode_TransformDecimalAndSpaceToASCII() used for floats and complexes (which gives another case of "sign in the middle") too.
@picnixz, @skirpichev, I tagged you for reviews because I thought you may be interested now that it is ready :-)
I'm particularly unsure about whether I missed or added unnecessary tests, and whether the documentation changes are good.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with minor nitpicks.
Maybe you can do docs more compact. See suggestions as an example.
Alternatively, omit just "(ASCII plus sign)" clarifications. There shouldn't be much confusion. Visual difference for '-' and '−' is less apparent.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note also, that we have a separate parsing from string code in the fromhex() class method.
I don't see good reasons to reject new sign character here, if we are going to support in the float constructor.
| def test_float(self): | ||
| self.assertEqual(float(3.14), 3.14) | ||
| self.assertEqual(float(314), 314.0) | ||
| self.assertEqual(float(" 3.14 "), 3.14) |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can add here also tests for parsing floats in scientific notation, with exponent.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll address this on the weekend.