From aaae5662311850646bcf81097de5fbdf0e718360 Mon Sep 17 00:00:00 2001 From: "kenny the :/" Date: Fri, 12 Jan 2024 20:16:53 +0800 Subject: [PATCH] Raise error on power with negative number (#5143) --- Lib/test/test_complex.py | 2 -- vm/src/builtins/complex.rs | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py index 72999c2f7..b26dd00d8 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -236,8 +236,6 @@ class ComplexTest(unittest.TestCase): for a, b in ZERO_DIVISION: self.assertRaises(TypeError, divmod, a, b) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_pow(self): self.assertAlmostEqual(pow(1+1j, 0+0j), 1.0) self.assertAlmostEqual(pow(0+0j, 2+0j), 0.0) diff --git a/vm/src/builtins/complex.rs b/vm/src/builtins/complex.rs index 609dcb9b6..4a3125c13 100644 --- a/vm/src/builtins/complex.rs +++ b/vm/src/builtins/complex.rs @@ -103,7 +103,7 @@ fn inner_div(v1: Complex64, v2: Complex64, vm: &VirtualMachine) -> PyResult PyResult { if v1.is_zero() { - return if v2.im != 0.0 { + return if v2.re < 0.0 || v2.im != 0.0 { let msg = format!("{v1} cannot be raised to a negative or complex power"); Err(vm.new_zero_division_error(msg)) } else if v2.is_zero() {