mypy doesn't understand `six.with_metaclass` #1764
Comments
@gvanrossum Do you believe this could be solved with the hypothetical plugin system in #1240 or is |
I think this should probably just be special-cased for six. Dynamically
created base classes aren't really mypy's core competency, but we should
handle at least some common cases.
|
This should probably be looked at again now that #2475 has been merged |
More issues:
from typing import *
from typing import GenericMeta
import six
class _DestroyableMeta(type): pass
@six.add_metaclass(_DestroyableMeta)
class Destroyable:
pass
T_co = TypeVar('T_co', bound='Destroyable', covariant=True)
class ArcMeta(GenericMeta, _DestroyableMeta):
pass
@six.add_metaclass(ArcMeta)
class Arc(Generic[T_co], Destroyable):
pass This passes with
|
Maybe this should be filed in the typing issue tracker? |
I think it is not something we can fix. |
Thinking about this more, Ivan is of course right that
I intend to fix both by hard-coding checks for these two There's also the issue that mypy accepted this, which doesn't work at runtime:
To address this we ought to duplicate Python's metaclass compatibility check. I think that's a lower priority though. |
I suspect the plugin architecture won't work here because metaclasses are computed before type checking begins. |
FWIW I forked issue #3365 (with lower priority) so we can focus here on adding support for (BTW Thanks to @TRManderson for laying the groundwork here -- it was pretty easy to special-case |
Fixes #1764. This doesn't add support for @six.add_metaclass(M) -- if that's required we'll add it later (we should open a separate issue for that). It does support generics (at least in the base classes).
Example:
In this case, mypy returns
error: Invalid base class
. However, in my larger project it actually causedmypy
to crash while checking a type derived from theTest
analogue. Unfortunately I wasn't able to reproduce this in a small example, but switching to@six.add_metaclass
fixed the problem.The text was updated successfully, but these errors were encountered: