Fixed some ruff warnings: requests without timeout and naming not complying with PEP

This commit is contained in:
Vincent Emonet 2023-07-09 12:38:03 +02:00
parent bf18dcbcf9
commit 1c0fb597fb
7 changed files with 25 additions and 31 deletions

View file

@ -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