There is no Python keyword for this - it is not Pythonic.
Is the class defined by a subclass using a flag called Py_TPFLAGS_BASETYPE , which can be set via API C.
This bit is set when a type can be used as the base type of another type. If this bit is clear, the type cannot be subtyped (similar to the "final" class in Java).
However, you can emulate the behavior using only Python code if you want:
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
A source
source share