Uh oh!
There was an error while loading. Please reload this page.
typing: remove metaclass from Sized - #9058
Conversation
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
sobolevn
left a comment
There was a problem hiding this comment.
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 |
srittau
commented
Nov 1, 2022
Wouldn't it make more sense to fix this in mypy? |
sobolevn
commented
Nov 1, 2022
I agree, this looks like a mypy bug, not a typeshed bug. |
JukkaL
commented
Nov 1, 2022
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. |
AlexWaygood
commented
Nov 1, 2022
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. |
JukkaL
commented
Nov 1, 2022
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: importabcfromtypingimportProtocolclassP(Protocol):
@abc.abstractmethoddeff(self) ->None: passclassC(P):
passC() # TypeError: Can't instantiate abstract class C with abstract method fI 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 |
JelleZijlstra
commented
Nov 1, 2022
Why does the metaclass cause problems for |
sobolevn
commented
Nov 1, 2022
Related #8998 |
erictraut
commented
Nov 1, 2022
Many classes in typeshed claim to derive from |
hauntsaninja
commented
Nov 2, 2022
Filed python/mypy#13986 for fixing the issue in mypy, merging this in the meantime, since srittau and alexwaygood are okay with it. |
JukkaL
commented
Nov 2, 2022
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)