Closed duck57 closed 1 year ago
Additional complication I fully expect you to close as out-of-scope (unless you plan to separate out @retry into its own package):
Add optional params to the retry function to specify which errors to retry and which to always raise. Use would be to save time on exceptions that make no sense to retry (which there aren't any in this word search, hence I expect this to be out-of-scope).
@duck57, the update to the @retry
decorator is pretty straightforward. The typing for wrapped decorators is ridiculous so I'm not going to try and please mypy at this time. I just wanted to respond back so you can see the implementation. Also, retries
defaults to max_fit_tries
so you don't have to supply an argument to the decorator unless you want it to be different.
def retry(retries: int = max_fit_tries):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
attempt = 0
while attempt < retries:
try:
return func(*args, **kwargs)
except Exception:
attempt += 1
return
return wrapper
return decorator
...
@retry(3)
def try_to_fit_word():
...
@duck57, I went ahead and added this and merged it into main
. I'm slowly making progress on the masking tests but there is a whole lot to test. Not sure when I'll get it done.
I want to use Word Search as the basis for a crossword generator (perhaps in December, more likely in February or March). The algorithm I'd use is:
max(sqrt(sum(len(word) for word in words)), len(longest_word))
@retry(3)
wrapper to try generating a puzzle with those dimensions 3 times.Changes to the code
@retry
function@retry
decorator ontry_to_fit_word
to be@retry(max_fit_tries)