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 Foo:
    pass
How does python prevent a class from being subclassed?