]> granicus.if.org Git - python/commitdiff
Issue #27832: Make _normalize parameter to Fraction.__init__ keyword-only.
authorMark Dickinson <dickinsm@gmail.com>
Tue, 23 Aug 2016 15:16:52 +0000 (16:16 +0100)
committerMark Dickinson <dickinsm@gmail.com>
Tue, 23 Aug 2016 15:16:52 +0000 (16:16 +0100)
Lib/fractions.py
Lib/test/test_fractions.py
Misc/NEWS

index a7120522cff3ba503158119aaf45d987336753ce..8330202d7037b3090f7e75dd4495fb1058712ed5 100644 (file)
@@ -81,7 +81,7 @@ class Fraction(numbers.Rational):
     __slots__ = ('_numerator', '_denominator')
 
     # We're immutable, so use __new__ not __init__
-    def __new__(cls, numerator=0, denominator=None, _normalize=True):
+    def __new__(cls, numerator=0, denominator=None, *, _normalize=True):
         """Constructs a Rational.
 
         Takes a string like '3/2' or '1.5', another Rational instance, a
index 664c7354694b9ff81e12f587b143c1304368376f..7905c367ba9dd24464c18809c87a146873ee5ba7 100644 (file)
@@ -150,6 +150,7 @@ class FractionTest(unittest.TestCase):
         self.assertRaises(TypeError, F, "3/2", 3)
         self.assertRaises(TypeError, F, 3, 0j)
         self.assertRaises(TypeError, F, 3, 1j)
+        self.assertRaises(TypeError, F, 1, 2, 3)
 
     @requires_IEEE_754
     def testInitFromFloat(self):
index dfe33fe0060cb6e10e324dbf8526ef08274af67e..6f31ec0bb6c089402a8efefb859bd2565351ef3a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -46,6 +46,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #27832: Make ``_normalize`` parameter to ``Fraction`` constuctor
+  keyword-only, so that ``Fraction(2, 3, 4)`` now raises ``TypeError``.
+
 - Issue #27539: Fix unnormalised ``Fraction.__pow__`` result in the case
   of negative exponent and negative base.