You can simulate the same effect from Python 3.x quite easily:
class Final(type):
def __new__(cls, name, bases, classdict):
for b in bases:
if isinstance(b, Final):
raise TypeError("type '{0}' is not an acceptable base type".format(b.__name__))
return type.__new__(cls, name, bases, dict(classdict))
class C(metaclass=Final): pass
class D(C): pass
will give the following output:
Traceback (most recent call last):
File "C:Tempfinal.py", line 10, in <module>
class D(C): pass
File "C:Tempfinal.py", line 5, in __new__
raise TypeError("type '{0}' is not an acceptable base type".format(b.__name__))
TypeError: type 'C' is not an acceptable base type
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…