changeset: 102834:902e82f71880 parent: 102832:485d7c341386 parent: 102833:7eea5b87f5fa user: Mark Dickinson date: Mon Aug 22 10:56:06 2016 +0100 files: Lib/fractions.py Lib/test/test_fractions.py Misc/ACKS Misc/NEWS description: Issue #27539: Merge from 3.5. diff -r 485d7c341386 -r 902e82f71880 Lib/fractions.py --- a/Lib/fractions.py Sun Aug 21 20:52:26 2016 -0700 +++ b/Lib/fractions.py Mon Aug 22 10:56:06 2016 +0100 @@ -460,10 +460,14 @@ return Fraction(a._numerator ** power, a._denominator ** power, _normalize=False) - else: + elif a._numerator >= 0: return Fraction(a._denominator ** -power, a._numerator ** -power, _normalize=False) + else: + return Fraction((-a._denominator) ** -power, + (-a._numerator) ** -power, + _normalize=False) else: # A fractional power will generally produce an # irrational number. diff -r 485d7c341386 -r 902e82f71880 Lib/test/test_fractions.py --- a/Lib/test/test_fractions.py Sun Aug 21 20:52:26 2016 -0700 +++ b/Lib/test/test_fractions.py Mon Aug 22 10:56:06 2016 +0100 @@ -356,6 +356,19 @@ z = pow(F(-1), F(1, 2)) self.assertAlmostEqual(z.real, 0) self.assertEqual(z.imag, 1) + # Regression test for #27539. + p = F(-1, 2) ** 0 + self.assertEqual(p, F(1, 1)) + self.assertEqual(p.numerator, 1) + self.assertEqual(p.denominator, 1) + p = F(-1, 2) ** -1 + self.assertEqual(p, F(-2, 1)) + self.assertEqual(p.numerator, -2) + self.assertEqual(p.denominator, 1) + p = F(-1, 2) ** -2 + self.assertEqual(p, F(4, 1)) + self.assertEqual(p.numerator, 4) + self.assertEqual(p.denominator, 1) def testMixedArithmetic(self): self.assertTypedEquals(F(11, 10), F(1, 10) + 1) diff -r 485d7c341386 -r 902e82f71880 Misc/ACKS --- a/Misc/ACKS Sun Aug 21 20:52:26 2016 -0700 +++ b/Misc/ACKS Mon Aug 22 10:56:06 2016 +0100 @@ -218,6 +218,7 @@ Ralph Butler Laurent De Buyst Zach Byrne +Vedran Čačić Nicolas Cadou Jp Calderone Arnaud Calmettes diff -r 485d7c341386 -r 902e82f71880 Misc/NEWS --- a/Misc/NEWS Sun Aug 21 20:52:26 2016 -0700 +++ b/Misc/NEWS Mon Aug 22 10:56:06 2016 +0100 @@ -38,6 +38,9 @@ Library ------- +- Issue #27539: Fix unnormalised ``Fraction.__pow__`` result in the case + of negative exponent and negative base. + - Issue #21718: cursor.description is now available for queries using CTEs. - Issue #27819: In distutils sdists, simply produce the "gztar" (gzipped tar