summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2016-08-22 09:56:06 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2016-08-22 09:56:06 (GMT)
commit0add84b9b855c10e9c6434286c2b1157a754a39f (patch)
treeb17328d4cb3258611a6617e0a14ad4c98ff03431
parentdc65c685249758c576f3fd915f7f913cdc0a0d2b (diff)
parent844796530a21f2a8689f2b9e01035d4a64a95275 (diff)
downloadcpython-0add84b9b855c10e9c6434286c2b1157a754a39f.zip
cpython-0add84b9b855c10e9c6434286c2b1157a754a39f.tar.gz
cpython-0add84b9b855c10e9c6434286c2b1157a754a39f.tar.bz2
Issue #27539: Merge from 3.5.
-rw-r--r--Lib/fractions.py6
-rw-r--r--Lib/test/test_fractions.py13
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
4 files changed, 22 insertions, 1 deletions
diff --git a/Lib/fractions.py b/Lib/fractions.py
index 64d746b..a712052 100644
--- a/Lib/fractions.py
+++ b/Lib/fractions.py
@@ -460,10 +460,14 @@ class Fraction(numbers.Rational):
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 --git a/Lib/test/test_fractions.py b/Lib/test/test_fractions.py
index 73d2dd3..664c735 100644
--- a/Lib/test/test_fractions.py
+++ b/Lib/test/test_fractions.py
@@ -356,6 +356,19 @@ class FractionTest(unittest.TestCase):
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 --git a/Misc/ACKS b/Misc/ACKS
index af993f7..9cc1c1e 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -218,6 +218,7 @@ Katherine Busch
Ralph Butler
Laurent De Buyst
Zach Byrne
+Vedran Čačić
Nicolas Cadou
Jp Calderone
Arnaud Calmettes
diff --git a/Misc/NEWS b/Misc/NEWS
index cefe831..ff677e0 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -38,6 +38,9 @@ Core and Builtins
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