diff options
author | Marc Tamlyn <marc.tamlyn@gmail.com> | 2014-02-09 11:10:05 +0000 |
---|---|---|
committer | Marc Tamlyn <marc.tamlyn@gmail.com> | 2014-02-09 11:23:09 +0000 |
commit | 80cd64ee17191ffb235c5850a8fa60cae96c1b89 (patch) | |
tree | 8d7166fcc3e9b956a9d912f2c96d6200607cf7a9 /tests/decorators | |
parent | 97a8fd4682b27a3a9f280e661e58db4bae55590a (diff) | |
download | django-80cd64ee17191ffb235c5850a8fa60cae96c1b89.tar.gz |
Fixed #21247 -- Made method_decorator play nicely with descriptors
When a method decorator was used in conjunction with a decorator
implemented as a descriptor, method_decorator did not correctly respect
the method binding.
Thanks for Graham Dumpleton for the report and initial patch.
Diffstat (limited to 'tests/decorators')
-rw-r--r-- | tests/decorators/tests.py | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/tests/decorators/tests.py b/tests/decorators/tests.py index e72e6cfee3..4a49dcc71d 100644 --- a/tests/decorators/tests.py +++ b/tests/decorators/tests.py @@ -232,9 +232,45 @@ class MethodDecoratorTests(TestCase): def method(self): return True - # t = Test() self.assertEqual(Test().method(), False) + def test_descriptors(self): + + def original_dec(wrapped): + def _wrapped(arg): + return wrapped(arg) + + return _wrapped + + method_dec = method_decorator(original_dec) + + class bound_wrapper(object): + def __init__(self, wrapped): + self.wrapped = wrapped + self.__name__ = wrapped.__name__ + + def __call__(self, arg): + return self.wrapped(arg) + + def __get__(self, instance, owner): + return self + + class descriptor_wrapper(object): + def __init__(self, wrapped): + self.wrapped = wrapped + self.__name__ = wrapped.__name__ + + def __get__(self, instance, owner): + return bound_wrapper(self.wrapped.__get__(instance, owner)) + + class Test(object): + @method_dec + @descriptor_wrapper + def method(self, arg): + return arg + + self.assertEqual(Test().method(1), 1) + class XFrameOptionsDecoratorsTests(TestCase): """ |