bpo-24234: implement complex.__complex__#27887
Merged
mdickinson merged 6 commits intoAug 23, 2021
Merged
Conversation
Member
Author
|
Hmm; there's an annoying Given that there have probably been other docstrings added to builtins since this was last touched (e.g., |
corona10
reviewed
Aug 22, 2021
corona10
left a comment
Member
There was a problem hiding this comment.
@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)
corona10
reviewed
Aug 22, 2021
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
Member
Author
Thanks! Done. |
…complex' into bpo-24234-implement-complex-complex
corona10
approved these changes
Aug 22, 2021
corona10
left a comment
Member
There was a problem hiding this comment.
(.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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements the
__complex__method for thecomplextype. 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 objectxcan be used as a complex number if its type implements at least one of__index__,__float__or__complex__.https://bugs.python.org/issue24234