Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. def makeFun(name, *args):
  2. exec("""def {}({}): raise NotImplementedError("'{}' is not implemented!")""".format(name, ', '.join(args), name))
  3. return locals()[name]
  4.  
  5. class ABC(type):
  6. def __init__(cls, name, bases, dct):
  7. for k, v in cls.__dict__.items():
  8. if not k.startswith("__") and callable(v):
  9. setattr(cls, k, makeFun(k, *v.__code__.co_varnames))
  10.  
  11. class Class(metaclass=ABC):
  12. def __init__(self, **kwargs):
  13. pass
  14.  
  15. def shouldFail(self, a, b):
  16. pass
  17.  
  18. a = Class()
  19. try:
  20. a.shouldFail(1, 2)
  21. except NotImplementedError as e:
  22. print(str(e))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement