mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2025-05-04 20:30:39 +00:00
Fixed some ruff warnings: requests without timeout and naming not complying with PEP
This commit is contained in:
parent
bf18dcbcf9
commit
1c0fb597fb
7 changed files with 25 additions and 31 deletions
|
@ -3,7 +3,7 @@
|
|||
import pycld2 as cld2
|
||||
|
||||
|
||||
class UnknownLanguage(Exception):
|
||||
class UnknownLanguageError(Exception):
|
||||
pass
|
||||
|
||||
class Language:
|
||||
|
@ -57,9 +57,9 @@ class Detector:
|
|||
if not reliable:
|
||||
self.reliable = False
|
||||
reliable, index, top_3_choices = cld2.detect(text, bestEffort=True)
|
||||
|
||||
|
||||
if not self.quiet and not reliable:
|
||||
raise UnknownLanguage("Try passing a longer snippet of text")
|
||||
raise UnknownLanguageError("Try passing a longer snippet of text")
|
||||
|
||||
self.languages = [Language(x) for x in top_3_choices]
|
||||
self.language = self.languages[0]
|
||||
|
@ -69,4 +69,4 @@ class Detector:
|
|||
text = f"Prediction is reliable: {self.reliable}\n"
|
||||
text += "\n".join([f"Language {i+1}: {str(l)}"
|
||||
for i,l in enumerate(self.languages)])
|
||||
return text
|
||||
return text
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue