Skip to content

Commit

Permalink
fix: Fix parameter mismatch in EPUBBookLoaderHelper.translate_with_ba…
Browse files Browse the repository at this point in the history
…ckoff

- Fix TypeError when calling translate_with_backoff with multiple arguments
- Add proper parameter handling in the decorated method
- Add jitter=None to prevent extra parameters from backoff decorator
- Improve code readability and error handling
  • Loading branch information
angenpn committed Nov 6, 2024
1 parent 9261d92 commit 0b5e5f4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions book_maker/loader/helper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from copy import copy
import backoff
import logging
from copy import copy

logging.basicConfig(level=logging.WARNING)
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -37,9 +37,10 @@ def insert_trans(self, p, text, translation_style="", single_translate=False):
Exception,
on_backoff=lambda details: logger.warning(f"retry backoff: {details}"),
on_giveup=lambda details: logger.warning(f"retry abort: {details}"),
jitter=None
)
def translate_with_backoff(self, **kwargs):
return self.translate_model.translate(**kwargs)
def translate_with_backoff(self, text, context_flag=False):
return self.translate_model.translate(text, context_flag)

def deal_new(self, p, wait_p_list, single_translate=False):
self.deal_old(wait_p_list, single_translate, self.context_flag)
Expand Down Expand Up @@ -128,4 +129,4 @@ def not_trans(s):
is_text_digit_and_space(s),
is_text_isbn(s),
]
)
)

0 comments on commit 0b5e5f4

Please sign in to comment.