tenacity icon indicating copy to clipboard operation
tenacity copied to clipboard

Fix issue 211

Open duboism opened this issue 6 years ago • 7 comments

This PR implements type check in operators as described in #211 .

duboism avatar Jan 10 '20 14:01 duboism

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).

duboism avatar Jan 28 '20 12:01 duboism

LGTM but I'm on the fence here. Not sure it's worth doing anything TBH.

jd avatar Jan 28 '20 13:01 jd

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.

asqui avatar Apr 22 '20 15:04 asqui

⚠️ No release notes detected. Please make sure to use reno to add a changelog entry.

mergify[bot] avatar Mar 11 '21 09:03 mergify[bot]

I added a changelog entry as required.

duboism avatar Mar 11 '21 20:03 duboism

I have noticed that I don't check types in wait_chain but I can't remember why.

duboism avatar Mar 11 '21 20:03 duboism

I have added the check in wait_chain. I think it can't hurt.

duboism avatar Mar 18 '21 18:03 duboism

Hum, I had the feeling that you were OK to merge this. Changed your mind ?

duboism avatar Sep 21 '22 12:09 duboism