Skip to content

Impossible to specify a metaclass for a Generic class #3720

Description

@rowillia

Not sure if this issue should go here or in https://github.com/python/typing

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.

from typing import Generic, TypeVar

class FooMeta(type):
    pass

_T = TypeVar('_T')

class Foo(Generic[_T], metaclass=FooMeta):
    pass

This passes MyPy just fine, but fails at runtime with:

$ python3.6 test_generics.py
Traceback (most recent call last):
  File "test_generics.py", line 8, in <module>
    class Foo(Generic[_T], metaclass=FooMeta):
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions