diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2024-01-13 18:22:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-13 18:22:31 (GMT) |
commit | 41edd371606109e93ce9d73c053109085f740d1b (patch) | |
tree | bf29c202f16a4be980e5f58a29e327c90a798b9e /Lib/test/test_fractions.py | |
parent | 25af45d9a4d9e94cd69b8a2008102376d121789f (diff) | |
download | cpython-41edd371606109e93ce9d73c053109085f740d1b.zip cpython-41edd371606109e93ce9d73c053109085f740d1b.tar.gz cpython-41edd371606109e93ce9d73c053109085f740d1b.tar.bz2 |
[3.11] gh-114014: Update `fractions.Fraction()`'s rational parsing regex (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>
Diffstat (limited to 'Lib/test/test_fractions.py')
-rw-r--r-- | Lib/test/test_fractions.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_fractions.py b/Lib/test/test_fractions.py index fc46e86..22dbd1e 100644 --- a/Lib/test/test_fractions.py +++ b/Lib/test/test_fractions.py @@ -259,6 +259,30 @@ class FractionTest(unittest.TestCase): self.assertRaisesMessage( ValueError, "Invalid literal for Fraction: '1.1e+1__1'", F, "1.1e+1__1") + self.assertRaisesMessage( + ValueError, "Invalid literal for Fraction: '123.dd'", + F, "123.dd") + self.assertRaisesMessage( + ValueError, "Invalid literal for Fraction: '123.5_dd'", + F, "123.5_dd") + self.assertRaisesMessage( + ValueError, "Invalid literal for Fraction: 'dd.5'", + F, "dd.5") + self.assertRaisesMessage( + ValueError, "Invalid literal for Fraction: '7_dd'", + F, "7_dd") + self.assertRaisesMessage( + ValueError, "Invalid literal for Fraction: '1/dd'", + F, "1/dd") + self.assertRaisesMessage( + ValueError, "Invalid literal for Fraction: '1/123_dd'", + F, "1/123_dd") + self.assertRaisesMessage( + ValueError, "Invalid literal for Fraction: '789edd'", + F, "789edd") + self.assertRaisesMessage( + ValueError, "Invalid literal for Fraction: '789e2_dd'", + F, "789e2_dd") # Test catastrophic backtracking. val = "9"*50 + "_" self.assertRaisesMessage( |