diff options
author | Mark Dickinson <mdickinson@enthought.com> | 2021-08-23 08:15:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-23 08:15:49 (GMT) |
commit | 6082bb5addab93755ab6e2bd2ed6021b391e10d1 (patch) | |
tree | ef109d492632072d919a7ebeb2ce89342a2babdb /Lib | |
parent | eec340ea3af27887fcaac4029ebdee99f3713bff (diff) | |
download | cpython-6082bb5addab93755ab6e2bd2ed6021b391e10d1.zip cpython-6082bb5addab93755ab6e2bd2ed6021b391e10d1.tar.gz cpython-6082bb5addab93755ab6e2bd2ed6021b391e10d1.tar.bz2 |
bpo-24234: implement complex.__complex__ (GH-27887)
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_complex.py | 12 | ||||
-rw-r--r-- | Lib/test/test_doctest.py | 2 | ||||
-rw-r--r-- | Lib/test/test_typing.py | 2 |
3 files changed, 14 insertions, 2 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py index abd7e39..1cd025e 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -499,6 +499,18 @@ class ComplexTest(unittest.TestCase): self.assertEqual(complex(complex1(1j)), 2j) self.assertRaises(TypeError, complex, complex2(1j)) + def test___complex__(self): + z = 3 + 4j + self.assertEqual(z.__complex__(), z) + self.assertEqual(type(z.__complex__()), complex) + + class complex_subclass(complex): + pass + + z = complex_subclass(3 + 4j) + self.assertEqual(z.__complex__(), 3 + 4j) + self.assertEqual(type(z.__complex__()), complex) + @support.requires_IEEE_754 def test_constructor_special_numbers(self): class complex2(complex): diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py index 8f761d7..571dc78 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -668,7 +668,7 @@ plain ol' Python and is guaranteed to be available. >>> import builtins >>> tests = doctest.DocTestFinder().find(builtins) - >>> 816 < len(tests) < 836 # approximate number of objects with docstrings + >>> 820 < len(tests) < 840 # approximate number of objects with docstrings True >>> real_tests = [t for t in tests if len(t.examples) > 0] >>> len(real_tests) # objects that actually have doctests diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 3bd5894..84521ee 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -1533,11 +1533,11 @@ class ProtocolTests(BaseTestCase): def test_supports_complex(self): - # Note: complex itself doesn't have __complex__. class C: def __complex__(self): return 0j + self.assertIsSubclass(complex, typing.SupportsComplex) self.assertIsSubclass(C, typing.SupportsComplex) self.assertNotIsSubclass(str, typing.SupportsComplex) |