gh-114014: Update fractions.Fraction()'s rational parsing regex#114015
Conversation
Fixes pythongh-114014. `\d` can easily be mistyped as simply `d`. Add tests for it. ``` (?P<decimal>d*|\d+(_\d+)*) ^^ ```
mdickinson
left a comment
There was a problem hiding this comment.
Thank you for this PR! The fix and the new tests look good to me. There's a PEP8 nit in about comments in the fractions.py file. We also need a news entry - are you in a position to add that? (I can create the news entry if you prefer.)
|
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 |
|
Random observation: the subpattern |
Make sure the comments in the regex are 2 spaces away from the content.
I considered that, but the |
Yep, agreed - it's good to be conservative with bug fixes, especially those that'll be backported to older Python versions. |
|
I have made the requested changes; please review again. |
Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
|
Thanks @thatbirdguythatuknownot for the PR, and @mdickinson for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
…ex (pythonGH-114015) Fix a bug in the regex used for parsing a string input to the `fractions.Fraction` constructor. That bug led to an inconsistent exception message being given for some inputs. --------- (cherry picked from commit dd56b57) Co-authored-by: Crowthebird <78076854+thatbirdguythatuknownot@users.noreply.github.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
|
Sorry, @thatbirdguythatuknownot and @mdickinson, I could not cleanly backport this to |
|
GH-114023 is a backport of this pull request to the 3.12 branch. |
…ex (python#114015) Fix a bug in the regex used for parsing a string input to the `fractions.Fraction` constructor. That bug led to an inconsistent exception message being given for some inputs. --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
|
GH-114025 is a backport of this pull request to the 3.11 branch. |
|
I wasn't able to cajole |
|
GH-114025 is a backport of this pull request to the 3.11 branch. |
…gex (GH-114015) (#114023) Fix a bug in the regex used for parsing a string input to the `fractions.Fraction` constructor. That bug led to an inconsistent exception message being given for some inputs. --------- (cherry picked from commit dd56b57) Co-authored-by: Crowthebird <78076854+thatbirdguythatuknownot@users.noreply.github.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Mark Dickinson <dickinsm@gmail.com> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
…gex (GH-114015) (#114025) Fix a bug in the regex used for parsing a string input to the `fractions.Fraction` constructor. That bug led to an inconsistent exception message being given for some inputs. --------- Co-authored-by: Crowthebird <78076854+thatbirdguythatuknownot@users.noreply.github.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
…ex (python#114015) Fix a bug in the regex used for parsing a string input to the `fractions.Fraction` constructor. That bug led to an inconsistent exception message being given for some inputs. --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
…ex (python#114015) Fix a bug in the regex used for parsing a string input to the `fractions.Fraction` constructor. That bug led to an inconsistent exception message being given for some inputs. --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
…ex (python#114015) Fix a bug in the regex used for parsing a string input to the `fractions.Fraction` constructor. That bug led to an inconsistent exception message being given for some inputs. --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
Fixes #114014.
The previous regex caused unintentional inconsistency in error messages due to the below:
Which matches the character
dinstead of the intended digit set\d. Fix it by adding a backslash behindd.fractions.Fraction()initialization error with invalid string #114014