8000 [3.13] gh-86069: Add more PyNumber_InPlacePower() tests (GH-130111) by miss-islington · Pull Request #130211 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.13] gh-86069: Add more PyNumber_InPlacePower() tests (GH-130111) #130211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
< 8000 button type="submit" data-view-component="true" class="btn-sm btn"> Apply and reload
Diff view
36 changes: 35 additions & 1 deletion Lib/test/test_capi/test_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ def test_misc_multiply(self):
self.assertRaises(MemoryError, inplacemultiply, [1, 2], PY_SSIZE_T_MAX//2 + 1)

def test_misc_power(self):
# PyNumber_Power()
# PyNumber_Power(), PyNumber_InPlacePower()
power = _testcapi.number_power
inplacepower = _testcapi.number_inplacepower

class HasPow(WithDunder):
methname = '__pow__'
Expand All @@ -216,6 +217,39 @@ class HasPow(WithDunder):
self.assertRaises(TypeError, power, 4, 11, 1.25)
self.assertRaises(TypeError, power, 4, 11, HasPow.with_val(NotImplemented))
self.assertRaises(TypeError, power, 4, 11, object())
self.assertEqual(inplacepower(4, 11, 5), pow(4, 11, 5))
self.assertRaises(TypeError, inplacepower, 4, 11, 1.25)
self.assertRaises(TypeError, inplacepower, 4, 11, object())

class X:
def __pow__(*args):
return args

x = X()
self.assertEqual(power(x, 11), (x, 11))
self.assertEqual(inplacepower(x, 11), (x, 11))
self.assertEqual(power(x, 11, 5), (x, 11, 5))
self.assertEqual(inplacepower(x, 11, 5), (x, 11, 5))

class X:
def __rpow__(*args):
return args

x = X()
self.assertEqual(power(4, x), (x, 4))
self.assertEqual(inplacepower(4, x), (x, 4))
# XXX: Three-arg power doesn't use __rpow__.
self.assertRaises(TypeError, power, 4, x, 5)
self.assertRaises(TypeError, inplacepower, 4, x, 5)

class X:
def __ipow__(*args):
return args

x = X()
self.assertEqual(inplacepower(x, 11), (x, 11))
# XXX: In-place power doesn't pass the third arg to __ipow__.
self.assertEqual(inplacepower(x, 11, 5), (x, 11))

@cpython_only
def test_rshift_print(self):
Expand Down
Loading
0