Index: Lib/fractions.py =================================================================== --- Lib/fractions.py (revision 71808) +++ Lib/fractions.py (working copy) @@ -103,8 +103,14 @@ if denominator == 0: raise ZeroDivisionError('Fraction(%s, 0)' % numerator) - numerator = operator.index(numerator) - denominator = operator.index(denominator) + + try: + numerator, denominator = ( + numerator.numerator * denominator.denominator, + denominator.numerator * numerator.denominator + ) + except AttributeError: + raise TypeError("both arguments should be Rational instances") g = gcd(numerator, denominator) self._numerator = numerator // g self._denominator = denominator // g Index: Lib/test/test_fractions.py =================================================================== --- Lib/test/test_fractions.py (revision 71808) +++ Lib/test/test_fractions.py (working copy) @@ -60,12 +60,15 @@ self.assertEquals((7, 15), _components(F(7, 15))) self.assertEquals((10**23, 1), _components(F(10**23))) + self.assertEquals((3, 77), _components(F(F(3, 7), 11))) + self.assertEquals((-9, 5), _components(F(2, F(-10, 9)))) + self.assertEquals((2486, 2485), _components(F(F(22, 7), F(355, 113)))) + self.assertRaisesMessage(ZeroDivisionError, "Fraction(12, 0)", F, 12, 0) self.assertRaises(TypeError, F, 1.5) self.assertRaises(TypeError, F, 1.5 + 3j) - self.assertRaises(TypeError, F, F(1, 2), 3) self.assertRaises(TypeError, F, "3/2", 3) def testFromString(self):