bpo-24234: implement complex.__complex__ (GH-27887) · python/cpython@6082bb5 · GitHub
Skip to content

Commit 6082bb5

Browse files
mdickinsoncorona10
andauthored
bpo-24234: implement complex.__complex__ (GH-27887)
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
1 parent eec340e commit 6082bb5

6 files changed

Lines changed: 57 additions & 3 deletions

File tree

Lib/test/test_complex.py

Lines changed: 12 additions & 0 deletions

Lib/test/test_doctest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ def non_Python_modules(): r"""
668668
669669
>>> import builtins
670670
>>> tests = doctest.DocTestFinder().find(builtins)
671-
>>> 816 < len(tests) < 836 # approximate number of objects with docstrings
671+
>>> 820 < len(tests) < 840 # approximate number of objects with docstrings
672672
True
673673
>>> real_tests = [t for t in tests if len(t.examples) > 0]
674674
>>> len(real_tests) # objects that actually have doctests

Lib/test/test_typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1533,11 +1533,11 @@ def test_supports_float(self):
15331533

15341534
def test_supports_complex(self):
15351535

1536-
# Note: complex itself doesn't have __complex__.
15371536
class C:
15381537
def __complex__(self):
15391538
return 0j
15401539

1540+
self.assertIsSubclass(complex, typing.SupportsComplex)
15411541
self.assertIsSubclass(C, typing.SupportsComplex)
15421542
self.assertNotIsSubclass(str, typing.SupportsComplex)
15431543

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Implement the :meth:`__complex__` special method on the :class:`complex` type,
2+
so a complex number ``z`` passes an ``isinstance(z, typing.SupportsComplex)``
3+
check.

Objects/clinic/complexobject.c.h

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/complexobject.c

Lines changed: 21 additions & 0 deletions

0 commit comments

Comments
 (0)