-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add object.__subclasshook__
#9755
Conversation
d4b8c52
to
1858b0c
Compare
This comment has been minimized.
This comment has been minimized.
1858b0c
to
5bd96d5
Compare
This comment has been minimized.
This comment has been minimized.
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.
One the one hand, this is incorrect: neither abc.ABC
nor abc.ABCMeta
define __subclasshook__
. The reason why the super().__subclasshook__
call works is that it's actually builtins.object
that defines a __subclasshook__
method:
>>> object.__dict__["__subclasshook__"]
<method '__subclasshook__' of 'object' objects>
>>> object.__subclasshook__(int)
NotImplemented
On the other hand, calling __subclasshook__
makes no sense unless you're doing it on a class that has ABCMeta
as the metaclass. So I'm not sure I'd want to add it to the stub for builtins.object
. So maybe this is an acceptable "white lie".
I'm curious what other maintainers think on this. In any event, if we are going to do this, I think a comment in the stub would be warranted, since it isn't actually defined in the abc.ABC
class at runtime.
I'm also curious what the experts think. In my experience, it's better to be accurate (rather than the "white lie" that's here) since you don't know what someone might do. So, if you agree, I'll move the method to On the other hand, why is this on |
In my opinion, we should stay as close to the implementation as possible, except if there's a really good reason. I believe we should add |
Agree, we should add Possibly it shouldn't exist, but that's a decision to make on the CPython project. I don't understand the implementation of ABCs well enough to understand why the decision was made to add this method to |
Sounds good, let's move it to |
461c7a1
to
c3c8ba6
Compare
Makes sense, done! |
This comment has been minimized.
This comment has been minimized.
c3c8ba6
to
db4fd2d
Compare
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Consider:
It will fail because
__subclasshook__
is not found.