mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-38302: __pow__/__rpow__ now called when __ipow__ returns NotImplemented (#16459)
This commit is contained in:
parent
5e48e83688
commit
cc02b4f2e8
4 changed files with 73 additions and 21 deletions
|
@ -3903,6 +3903,48 @@ order (MRO) for bases """
|
|||
a = C()
|
||||
a **= 2
|
||||
|
||||
def test_ipow_returns_not_implemented(self):
|
||||
class A:
|
||||
def __ipow__(self, other):
|
||||
return NotImplemented
|
||||
|
||||
class B(A):
|
||||
def __rpow__(self, other):
|
||||
return 1
|
||||
|
||||
class C(A):
|
||||
def __pow__(self, other):
|
||||
return 2
|
||||
a = A()
|
||||
b = B()
|
||||
c = C()
|
||||
|
||||
a **= b
|
||||
self.assertEqual(a, 1)
|
||||
|
||||
c **= b
|
||||
self.assertEqual(c, 2)
|
||||
|
||||
def test_no_ipow(self):
|
||||
class B:
|
||||
def __rpow__(self, other):
|
||||
return 1
|
||||
|
||||
a = object()
|
||||
b = B()
|
||||
a **= b
|
||||
self.assertEqual(a, 1)
|
||||
|
||||
def test_ipow_exception_text(self):
|
||||
x = None
|
||||
with self.assertRaises(TypeError) as cm:
|
||||
x **= 2
|
||||
self.assertIn('unsupported operand type(s) for **=', str(cm.exception))
|
||||
|
||||
with self.assertRaises(TypeError) as cm:
|
||||
y = x ** 2
|
||||
self.assertIn('unsupported operand type(s) for **', str(cm.exception))
|
||||
|
||||
def test_mutable_bases(self):
|
||||
# Testing mutable bases...
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue