Skip to content

Commit 6426025

Browse files
committed
Add tests, update news entry
1 parent 8a357bb commit 6426025

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Lib/test/test_descr.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3897,14 +3897,24 @@ def test_ipow_returns_not_implemented(self):
38973897
class A:
38983898
def __ipow__(self, other):
38993899
return NotImplemented
3900-
class B:
3900+
3901+
class B(A):
39013902
def __rpow__(self, other):
39023903
return 1
3904+
3905+
class C(A):
3906+
def __pow__(self, other):
3907+
return 2
39033908
a = A()
39043909
b = B()
3910+
c = C()
3911+
39053912
a **= b
39063913
self.assertEqual(a, 1)
39073914

3915+
c **= b
3916+
self.assertEqual(c, 2)
3917+
39083918
def test_no_ipow(self):
39093919
class B:
39103920
def __rpow__(self, other):
@@ -3915,6 +3925,16 @@ def __rpow__(self, other):
39153925
a **= b
39163926
self.assertEqual(a, 1)
39173927

3928+
def test_ipow_exception_text(self):
3929+
x = None
3930+
with self.assertRaises(TypeError) as cm:
3931+
x **= 2
3932+
self.assertIn('unsupported operand type(s) for **=', str(cm.exception))
3933+
3934+
with self.assertRaises(TypeError) as cm:
3935+
y = x ** 2
3936+
self.assertIn('unsupported operand type(s) for **', str(cm.exception))
3937+
39183938
def test_mutable_bases(self):
39193939
# Testing mutable bases...
39203940

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
If :func:`operator.__ipow__` returns :const:`NotImplemented` :func:`operator.__rpow__` will be called now as expected.
1+
If :func:`object.__ipow__` returns :const:`NotImplemented`, the operator will correctly fall back to :func:`object.__pow__` and :func:`object.__rpow__` as expected.

0 commit comments

Comments
 (0)