-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
typing: remove metaclass from Sized #9058
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
Conversation
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
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.
Can we please add a regression test? This seems quite important to catch.
The existing mypy test will catch it if you run it with latest mypy. The change in behaviour on mypy side bisects back to python/mypy#13579 |
Wouldn't it make more sense to fix this in mypy? |
I agree, this looks like a mypy bug, not a typeshed bug. |
I agree that this looks like a mypy bug, but the metaclass declaration doesn't seem correct so this still PR seems reasonable: >>> type(Protocol)
<class 'typing._ProtocolMeta'> |
It does feel more correct than not having the metaclass declaration, though, since |
Also, the behavior is very ABCMeta-like:
That said, if this is not an easy fix in mypy, I'm fine with reverting for now. Edit: Reverting with a comment linking to the appropriate mypy issue. |
I've just realised that at runtime, all classes directly inheriting from But yeah, I agree with @srittau — whatever the case, it's not really a big deal, so I'm fine with this being merged for now. |
A subclass of Protocol is implicitly an ABC, so explicitly giving the metaclass seems redundant, and we don't do it consistently in typeshed right now -- many protocols don't have an explicit metaclass. Relevant example: import abc
from typing import Protocol
class P(Protocol):
@abc.abstractmethod
def f(self) -> None: pass
class C(P):
pass
C() # TypeError: Can't instantiate abstract class C with abstract method f I think that type checkers should infer the correct metaclass automatically. Mypy doesn't seem to do it right now. I've filed an issue about this: python/mypy#13979 |
Probably the reason why we specify the metaclass so consistently in |
Why does the metaclass cause problems for |
Related #8998 |
Many classes in typeshed claim to derive from |
Filed python/mypy#13986 for fixing the issue in mypy, merging this in the meantime, since srittau and alexwaygood are okay with it. |
To summarize the discussion above, this works around a bug in mypy and the original ABCMeta metaclass was correct, since |
This reverts commit a3ce512.
as per #8977 (comment)