Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There is one other thing that could break, but it would be a weird one. Which is hard to explain in prose, so here's some example code:

    class SomeMetaClass:
        def __new__(name, bases, attrs):
            pass

    class SomeClass(metaclass=SomeMetaClass):
        pass
Now suppose that SomeClass needs to use the typing module's mechanism for indicating a generic, so you could do an annotation like "SomeClass[SomeOtherType]". So you'd want to have SomeClass be a subclass of, typing.Generic[T]. That would, in Python 3 prior to 3.7, raise a TypeError due to metaclass conflict -- the generics in the typing module had their own base metaclasses. So you actually had to define an intermediate class to resolve the metaclass conflict, and do like so:

    class IntermediateMeta(SomeMetaClass, typing.GenericMeta):
        pass

    class SomeClass(metaclass=IntermediateMeta):
        pass
(this was weird and rare and GenericMeta was never documented)

Python 3.7 implemented PEP 560, which introduced the __class_getitem__ hook for implementing the behavior GenericMeta used to handle, and doing away with the need for the typing generics to use GenericMeta as their metaclass. So GenericMeta exists in Python 3.5 and 3.6, but no longer exists in Python 3.7, and anything which tries to reference it will break.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: