Fix issue 211
This PR implements type check in operators as described in #211 .
As proposed in #211, I removed wait_base.__radd__. This allows other classes to define their own addition with wait conditions (stop conditions don't define reverse operations for & and | so they are not concerned).
The example below illustrate this (in this case we add a wait_fixed object but it's for the purpose of illustration):
class ExtendTenacity(object):
def __init__(self, n):
self.n = n
def __add__(self, other):
return tenacity.wait_fixed(self.n) + other
def __radd__(self, other):
return self + other
try:
tenacity.wait_fixed(5) + 3
except TypeError:
print("Weird add detected")
ExtendTenacity(5) + tenacity.wait_fixed(5)
print("Normal add")
tenacity.wait_fixed(5) + ExtendTenacity(5)
print("Normal radd")
Note that this introduce an incompatible change: sum must start with wait_none (see 4d62a2b).
LGTM but I'm on the fence here. Not sure it's worth doing anything TBH.
As a relatively new user of Tenaticy I can say that the flexibility of configuration, whilst powerful, brings about the possibility of misconfiguring and getting unexpected behaviour.
This change seems to prevent one from shooting themselves in the foot, so seems a worthwhile improvement to me, purely from a usability / pit of success point of view.
⚠️ No release notes detected. Please make sure to use reno to add a changelog entry.
I added a changelog entry as required.
I have noticed that I don't check types in wait_chain but I can't remember why.
I have added the check in wait_chain. I think it can't hurt.
Hum, I had the feeling that you were OK to merge this. Changed your mind ?