Merged
Conversation
For two-parameter overload: - Change first parameter to complex | SupportsComplex | SupportsFloat - Change second parameter to complex | SupportsFloat (Python doesn't allow SupportsComplex for the second parameter, though it isn't clear why) - Add SupportsIndex to both parameters for Python >= 3.8 For one-parameter overload: - Remove SupportsIndex for Python < 3.8
Add `SupportsFloat` to one-parameter overload, per python#8440 (comment)
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Collaborator
|
Lol, we both changed the title :) |
Akuli
approved these changes
Aug 2, 2022
Collaborator
Akuli
left a comment
There was a problem hiding this comment.
Thanks! I used a script and all Python versions 3.6 to 3.10 to verify this.
my script
class SupportsFloat:
def __float__(self):
return 1.0
class SupportsComplex:
def __complex__(self):
return 1+2j
class SupportsIndex:
def __index__(self):
return 1
objects = {
"SupportsFloat": SupportsFloat(),
"SupportsComplex": SupportsComplex(),
"SupportsIndex": SupportsIndex(),
"float": 1.0,
"complex": 1+2j,
"int": 1,
}
#single_arg = []
#for name, obj in objects.items():
# try:
# complex(obj)
# except Exception:
# pass
# else:
# single_arg.append(name)
#print(single_arg)
double_arg = []
for name1, obj1 in objects.items():
for name2, obj2 in objects.items():
try:
complex(obj1, obj2)
except Exception:
pass
else:
double_arg.append((name1, name2))
import pprint
pprint.pprint(double_arg)| else: | ||
| @overload | ||
| def __new__( | ||
| cls: type[Self], real: complex | SupportsComplex | SupportsFloat = ..., imag: complex | SupportsFloat = ... |
Collaborator
There was a problem hiding this comment.
Also accepts int, but that's included implicitly in complex.
| @overload | ||
| def __new__( | ||
| cls: type[Self], | ||
| real: complex | SupportsComplex | SupportsFloat | SupportsIndex = ..., |
Collaborator
There was a problem hiding this comment.
I find it weird that SupportsComplex doesn't include complex.
Member
There was a problem hiding this comment.
You're not the only one — I believe this specific oddity was why they added complex.__complex__ in 3.11 :)
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.
Fix for issue #8440