Fixed #26287 -- Added support for addition operations to SimpleLazyObject.

This commit is contained in:
Theo Alexiou 2022-02-05 20:28:09 +01:00 committed by Mariusz Felisiak
parent 4c76ffc2d6
commit f9ec777a82
3 changed files with 18 additions and 1 deletions

View File

@ -432,6 +432,12 @@ class SimpleLazyObject(LazyObject):
return result
return copy.deepcopy(self._wrapped, memo)
__add__ = new_method_proxy(operator.add)
@new_method_proxy
def __radd__(self, other):
return other + self
def partition(predicate, values):
"""

View File

@ -294,7 +294,7 @@ URLs
Utilities
~~~~~~~~~
* ...
* ``SimpleLazyObject`` now supports addition operations.
Validators
~~~~~~~~~~

View File

@ -317,6 +317,17 @@ class SimpleLazyObjectTestCase(LazyObjectTestCase):
self.assertIsInstance(obj._wrapped, int)
self.assertEqual(repr(obj), "<SimpleLazyObject: 42>")
def test_add(self):
obj1 = self.lazy_wrap(1)
self.assertEqual(obj1 + 1, 2)
obj2 = self.lazy_wrap(2)
self.assertEqual(obj2 + obj1, 3)
self.assertEqual(obj1 + obj2, 3)
def test_radd(self):
obj1 = self.lazy_wrap(1)
self.assertEqual(1 + obj1, 2)
def test_trace(self):
# See ticket #19456
old_trace_func = sys.gettrace()