-
Notifications
You must be signed in to change notification settings - Fork 258
Impossible to specify a metaclass for a Generic class #449
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
As a workaround in cases where possible, one can just do: from typing import Generic, TypeVar, GenericMeta
class FooMeta(type):
pass
class GenericFooMeta(GenericMeta, FooMeta):
pass
T = TypeVar('T')
class Foo(Generic[T], metaclass=GenericFooMeta):
pass |
We recently encountered this in a case where a superclass we don't control used |
Yes. Moreover |
This is fixed in Python 3.7+ and we can't really do anything for older versions, so I think this can be closed. |
Below is a contrived example. In the real world I might not actually control the metaclass for
Foo
or I may be inheriting from some other class that also has a metaclass.This passes MyPy just fine, but fails at runtime with:
Moved from python/mypy#3720
The text was updated successfully, but these errors were encountered: