2

The signature is: super([type[, object-or-type]]). And its doc says:

If the second argument is omitted, the super object returned is unbound. If the second argument is an object, isinstance(obj, type) must be true. If the second argument is a type, issubclass(type2, type) must be true (this is useful for classmethods).

According to the doc, if someone wants super(metatype, type), the second argument is a type, so issubclass(type, metatype) must be true. But my test program shows it can be false:

#!/usr/bin/env python3

class M0(type):
    def wtf(self):
        print('M0')

class M1(M0):
    def wtf(self):
        print('M1')

class C0(metaclass=M1):
    @classmethod
    def wtf(cls):
        assert issubclass(C0, M1) == False
        super(M1, C0).wtf()

C0.wtf()

Is this guaranteed or undefined?

Cyker
  • 9,946
  • 8
  • 65
  • 93
  • Interesting question, I thought it's undefined behavior, waiting for others' answers. – Menglong Li Jan 28 '19 at 06:22
  • The difference, I suppose, lies between `type` and `object`. `C0` is an instance of type `M1`, not a subclass of `M1`. For more details on metaclasses that you used in your example, have a look at https://stackoverflow.com/questions/100003/what-are-metaclasses-in-python – JRajan Jan 28 '19 at 06:45

0 Answers0