#!/usr/local/bin/python3
from types import MethodType

class C(object):
  def __init__(self):
    pass
    self.sss = MethodType(s, self)

def s(self, key, value):
  print('set')
  if key == 'a':
    raise ValueError
  self.__dict__[key] = value

c = C()
c.sss('b', 1)
print(c.a)