Advertisement
treyhunner

classonly decorator

Mar 15th, 2019
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. from functools import wraps
  2.  
  3.  
  4. class classonly:
  5.     def __init__(self, func):
  6.         self.func = func
  7.     def __get__(self, obj, klass=None):
  8.         if obj is not None:
  9.             raise TypeError("This method cannot be called from a class instance.")
  10.         @wraps(self.func)
  11.         def wrapper(*args):
  12.             return self.func(klass, *args)
  13.         return wrapper
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement