From da46599143408be58c1845b8c82cacbae0bb56c0 Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Wed, 27 Jun 2018 08:46:07 -0700 Subject: [2.1.x] Refs #29253 -- Fixed method_decorator() crash if decorator sets a new attribute. Regression in fdc936c9130cf4fb5d59869674b9a31cc79a7999. Backport of f434f5b84f7fcea9a76a551621ecce70786e2899 from master --- tests/decorators/tests.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/decorators/tests.py b/tests/decorators/tests.py index e8f6b8d2d5..aaa09c0056 100644 --- a/tests/decorators/tests.py +++ b/tests/decorators/tests.py @@ -271,6 +271,21 @@ class MethodDecoratorTests(SimpleTestCase): self.assertEqual(Test.method.__doc__, 'A method') self.assertEqual(Test.method.__name__, 'method') + def test_new_attribute(self): + """A decorator that sets a new attribute on the method.""" + def decorate(func): + func.x = 1 + return func + + class MyClass: + @method_decorator(decorate) + def method(self): + return True + + obj = MyClass() + self.assertEqual(obj.method.x, 1) + self.assertIs(obj.method(), True) + def test_bad_iterable(self): decorators = {myattr_dec_m, myattr2_dec_m} msg = "'set' object is not subscriptable" -- cgit v1.3