-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
bpo-24234: implement complex.__complex__ #27887
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
bpo-24234: implement complex.__complex__ #27887
Conversation
Hmm; there's an annoying
Given that there have probably been other docstrings added to builtins since this was last touched (e.g., |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mdickinson
I would like to suggest adding test in test_typing.py
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -1540,6 +1540,7 @@ def __complex__(self):
self.assertIsSubclass(C, typing.SupportsComplex)
self.assertNotIsSubclass(str, typing.SupportsComplex)
+ self.assertIsSubclass(complex, typing.SupportsComplex)
Misc/NEWS.d/next/Core and Builtins/2021-08-22-12-28-50.bpo-24234.n3oTdx.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
Thanks! Done. |
…complex' into bpo-24234-implement-complex-complex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(.oss) ➜ cpython git:(pr/27887) ✗ ./python.exe -m test test_typing.py test_comp
lex -R 3:3
0:00:00 load avg: 3.41 Run tests sequentially
0:00:00 load avg: 3.41 [1/2] test_typing
beginning 6 repetitions
123456
......
0:00:02 load avg: 3.41 [2/2] test_complex
beginning 6 repetitions
123456
......
== Tests result: SUCCESS ==
All 2 tests OK.
Total duration: 5.6 sec
Tests result: SUCCESS
LGTM, no leak was found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This PR implements the
__complex__
method for thecomplex
type. This slightly simplifies the check for whether a Python object can be used as a complex number, and means that that check can be implemented purely in terms of the existence of special methods - an objectx
can be used as a complex number if its type implements at least one of__index__
,__float__
or__complex__
.https://bugs.python.org/issue24234