Skip to content

Commit 6ee98ec

Browse files
committed
update classonlymethod
1 parent fd688bd commit 6ee98ec

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

‎uliweb/utils/common.py‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def get_caller(skip=None):
538538
if not found:
539539
return filename, lineno, funcname
540540

541-
class classonlymethod(object):
541+
class classonlymethod(classmethod):
542542
"""
543543
Use to limit the class method can only be called via class object, but not instance
544544
object
@@ -554,19 +554,12 @@ class classonlymethod(object):
554554
... a.p()
555555
... except Exception as e:
556556
... print e
557-
Method p can only be called with class object
557+
This method can only be called with class object.
558558
"""
559-
def __init__(self, func):
560-
self._func = func
561-
562-
def __get__(self, model_instance, model_class):
563-
from functools import partial, wraps
564-
565-
if model_instance:
566-
raise Exception("Method %s can only be called with class object" % self._func.__name__)
567-
else:
568-
f = partial(self._func, model_class)
569-
return wraps(self._func)(f)
559+
def __get__(self, instance, owner):
560+
if instance is not None:
561+
raise AttributeError("This method can only be called with class object.")
562+
return super(classonlymethod, self).__get__(instance, owner)
570563

571564
#if __name__ == '__main__':
572565
# log.info('Info: info')

0 commit comments

Comments
 (0)