fork download
  1. class ValidatorMeta(type):
  2. def __new__(mcs, name, bases, attrs):
  3. assert 'x' not in attrs, "Using properties isn't allowed"
  4. assert '__setattr__' not in attrs, "Using __setattr__ isn't allowed"
  5. return super().__new__(mcs, name, bases, attrs)
  6.  
  7. class SomeClass(metaclass=ValidatorMeta):
  8. @property
  9. def __dict__(self):
  10. return {'y': 5}
  11.  
  12. obj = SomeClass()
  13. obj.x = 3
  14. obj.y = 5
  15. assert vars(obj) == {'y': 5}
  16. print('You win!')
Success #stdin #stdout 0.01s 27704KB
stdin
Standard input is empty
stdout
You win!