From 6af6bfdab7dfd11edf5a3a6f6817e8141ba283ab Mon Sep 17 00:00:00 2001 From: Chris Moradi <37349208+chrismoradi@users.noreply.github.com> Date: Tue, 5 Oct 2021 10:25:49 -0700 Subject: [PATCH 1/2] Fix repr for complex numbers involving NaN --- Lib/test/test_complex.py | 2 -- vm/src/builtins/complex.rs | 7 +++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py index b72bd711b..e0ed859c5 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -460,8 +460,6 @@ class ComplexTest(unittest.TestCase): for num in nums: self.assertAlmostEqual((num.real**2 + num.imag**2) ** 0.5, abs(num)) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_repr_str(self): def test(v, expected, test_fn=self.assertEqual): test_fn(repr(v), expected) diff --git a/vm/src/builtins/complex.rs b/vm/src/builtins/complex.rs index dc87963d3..faf20c11f 100644 --- a/vm/src/builtins/complex.rs +++ b/vm/src/builtins/complex.rs @@ -305,10 +305,13 @@ impl PyComplex { #[pymethod(magic)] fn repr(&self) -> String { let Complex64 { re, im } = self.value; + // converting to lowercase to format "NaN" as "nan" if re == 0.0 { - format!("{}j", im) + format!("{}j", im).to_lowercase() + } else if im.is_nan() { + format!("({}+{:+}j)", re, im).to_lowercase() } else { - format!("({}{:+}j)", re, im) + format!("({}{:+}j)", re, im).to_lowercase() } } From 911de9791ae57f2535dd9a27eaef0cf206738785 Mon Sep 17 00:00:00 2001 From: Chris Moradi <37349208+chrismoradi@users.noreply.github.com> Date: Tue, 5 Oct 2021 10:56:55 -0700 Subject: [PATCH 2/2] cmath test passes too --- Lib/test/test_cmath.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py index cf5dbaf95..9e95a1c7f 100644 --- a/Lib/test/test_cmath.py +++ b/Lib/test/test_cmath.py @@ -160,8 +160,6 @@ class CMathTests(unittest.TestCase): self.assertAlmostEqual(cmath.e, e_expected, places=9, msg="cmath.e is {}; should be {}".format(cmath.e, e_expected)) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_infinity_and_nan_constants(self): self.assertEqual(cmath.inf.real, math.inf) self.assertEqual(cmath.inf.imag, 0.0)