summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2023-06-07 12:13:34 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-06-12 05:59:40 +0200
commitfd97b0471b19cb45c4346e4947dfa7e69ff06158 (patch)
tree71e4a78bf545c365b6eb8c4ee10dc647dd48a712
parent45466f11f200914cde2a4b5533441b93015ea14e (diff)
Allowed multiplication of lazy() objects with int return type.
-rw-r--r--django/utils/functional.py3
-rw-r--r--tests/utils_tests/test_functional.py1
2 files changed, 4 insertions, 0 deletions
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)