diff options
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/fractions.py | 2 | ||||
| -rw-r--r-- | Lib/test/test_fractions.py | 4 |
2 files changed, 2 insertions, 4 deletions
diff --git a/Lib/fractions.py b/Lib/fractions.py index 738a0d4..43b72ae 100644 --- a/Lib/fractions.py +++ b/Lib/fractions.py @@ -26,7 +26,7 @@ _RATIONAL_FORMAT = re.compile(r""" (?=\d|\.\d) # lookahead for digit or .digit (?P<num>\d*|\d+(_\d+)*) # numerator (possibly empty) (?: # followed by - (?:/(?P<denom>\d+(_\d+)*))? # an optional denominator + (?:\s*/\s*(?P<denom>\d+(_\d+)*))? # an optional denominator | # or (?:\.(?P<decimal>d*|\d+(_\d+)*))? # an optional fractional part (?:E(?P<exp>[-+]?\d+(_\d+)*))? # and optional exponent diff --git a/Lib/test/test_fractions.py b/Lib/test/test_fractions.py index fc46e86..7fa9dbe 100644 --- a/Lib/test/test_fractions.py +++ b/Lib/test/test_fractions.py @@ -162,6 +162,7 @@ class FractionTest(unittest.TestCase): def testFromString(self): self.assertEqual((5, 1), _components(F("5"))) self.assertEqual((3, 2), _components(F("3/2"))) + self.assertEqual((3, 2), _components(F("3 / 2"))) self.assertEqual((3, 2), _components(F(" \n +3/2"))) self.assertEqual((-3, 2), _components(F("-3/2 "))) self.assertEqual((13, 2), _components(F(" 013/02 \n "))) @@ -191,9 +192,6 @@ class FractionTest(unittest.TestCase): ValueError, "Invalid literal for Fraction: '/2'", F, "/2") self.assertRaisesMessage( - ValueError, "Invalid literal for Fraction: '3 /2'", - F, "3 /2") - self.assertRaisesMessage( # Denominators don't need a sign. ValueError, "Invalid literal for Fraction: '3/+2'", F, "3/+2") |
