Fixed #26287 -- Added support for addition operations to SimpleLazyObject.
This commit is contained in:
parent
4c76ffc2d6
commit
f9ec777a82
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -294,7 +294,7 @@ URLs
|
|||
Utilities
|
||||
~~~~~~~~~
|
||||
|
||||
* ...
|
||||
* ``SimpleLazyObject`` now supports addition operations.
|
||||
|
||||
Validators
|
||||
~~~~~~~~~~
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue