diff --git a/Lib/difflib.py b/Lib/difflib.py index 7c7e233b013a76..8f3cdaed9564d8 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -942,10 +942,12 @@ def _fancy_replace(self, a, alo, ahi, b, blo, bhi): cruncher.set_seq1(a[i]) # Ordering by cheapest to most expensive ratio is very # valuable, most often getting out early. - if (crqr() > best_ratio - and cqr() > best_ratio - and cr() > best_ratio): - best_i, best_j, best_ratio = i, j, cr() + if crqr() <= best_ratio or cqr() <= best_ratio: + continue + + ratio = cr() + if ratio > best_ratio: + best_i, best_j, best_ratio = i, j, ratio if best_i is None: # found nothing to synch on yet - move to next j