def immutable_meta(name, bases, dct):


    class Meta(type):

        def __init__(cls, name, bases, dct):
            type.__setattr__(cls, 'attr', set(dct.keys()))
type.__init__(cls, name, bases, dct)

def __setattr__(cls, attr, value):
    if attr not in cls.attr:
        raise AttributeError('Cannot assign attributes to this class')
return type.__setattr__(cls, attr, value)
return Meta(name, bases, dct)


class A(metaclass=immutable_meta):
    pass
b = 'test'
a = A()
a.c = 10
A.c = 20
Способы сделать класс неизменяемым в Python