diff options
Diffstat (limited to 'passlib')
-rw-r--r-- | passlib/tests/test_utils.py | 11 | ||||
-rw-r--r-- | passlib/utils/decor.py | 10 |
2 files changed, 11 insertions, 10 deletions
diff --git a/passlib/tests/test_utils.py b/passlib/tests/test_utils.py index ceea26a..2bc5c48 100644 --- a/passlib/tests/test_utils.py +++ b/passlib/tests/test_utils.py @@ -35,15 +35,18 @@ class MiscTest(TestCase): def test_classproperty(self): from passlib.utils.decor import classproperty + def xprop_func(cls): + return cls.xvar + class test(object): xvar = 1 - @classproperty - def xprop(cls): - return cls.xvar + + xprop = classproperty(xprop_func) self.assertEqual(test.xprop, 1) + prop = test.__dict__['xprop'] - self.assertIs(prop.im_func, prop.__func__) + self.assertIs(prop.__func__, xprop_func) def test_deprecated_function(self): from passlib.utils.decor import deprecated_function diff --git a/passlib/utils/decor.py b/passlib/utils/decor.py index aa40925..e1fd601 100644 --- a/passlib/utils/decor.py +++ b/passlib/utils/decor.py @@ -31,15 +31,12 @@ class classproperty(object): """Function decorator which acts like a combination of classmethod+property (limited to read-only properties)""" def __init__(self, func): - self.im_func = func + # XXX: rename to .fget to match property? + self.__func__ = func def __get__(self, obj, cls): - return self.im_func(cls) + return self.__func__(cls) - @property - def __func__(self): - """py3 compatible alias""" - return self.im_func class hybrid_method(object): """ @@ -48,6 +45,7 @@ class hybrid_method(object): """ def __init__(self, func): + # XXX: rename to .fget to match property? self.func = func update_wrapper(self, func) |