From fd97b0471b19cb45c4346e4947dfa7e69ff06158 Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Wed, 7 Jun 2023 12:13:34 +0100 Subject: [PATCH] Allowed multiplication of lazy() objects with int return type. --- django/utils/functional.py | 3 +++ tests/utils_tests/test_functional.py | 1 + 2 files changed, 4 insertions(+) diff --git a/django/utils/functional.py b/django/utils/functional.py index b78706e073..0bc641cb21 100644 --- a/django/utils/functional.py +++ b/django/utils/functional.py @@ -163,6 +163,9 @@ def lazy(func, *resultclasses): def __mod__(self, other): return self.__cast() % other + def __mul__(self, other): + return self.__cast() * other + # Add wrappers for all methods from resultclasses which haven't been # wrapped explicitly above. for resultclass in resultclasses: diff --git a/tests/utils_tests/test_functional.py b/tests/utils_tests/test_functional.py index 0fc6ee97da..c8b8fe5a3f 100644 --- a/tests/utils_tests/test_functional.py +++ b/tests/utils_tests/test_functional.py @@ -230,6 +230,7 @@ class FunctionalTests(SimpleTestCase): lazy_5 = lazy(lambda: 5, int) self.assertEqual(4 * lazy_5(), 20) self.assertEqual(lazy_4() * 5, 20) + self.assertEqual(lazy_4() * lazy_5(), 20) def test_lazy_mul_list(self): lazy_4 = lazy(lambda: [4], list)