Skip to content

Commit

Permalink
Change methods not using its bound instance to staticmethods
Browse files Browse the repository at this point in the history
  • Loading branch information
deepsource-autofix[bot] authored and Freed-Wu committed Jan 23, 2023
1 parent df47aa9 commit 7c6c971
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 22 deletions.
20 changes: 13 additions & 7 deletions src/translate_shell/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def __init__(self) -> None:
self.sleep_seconds: float = 0.1
self.clipboard: bool = True

@staticmethod
def process_input(
self,
text: str,
target_lang: str,
source_lang: str,
Expand All @@ -63,7 +63,8 @@ def process_input(
text, target_lang, source_lang, translators, is_repl
)

def process_output(self, translation: Translation) -> str:
@staticmethod
def process_output(translation: Translation) -> str:
"""Process output.
:param translation:
Expand All @@ -74,7 +75,8 @@ def process_output(self, translation: Translation) -> str:

return process_output(translation)

def get_clipper(self) -> list[str]:
@staticmethod
def get_clipper() -> list[str]:
"""Get clipper.
:rtype: list[str]
Expand All @@ -83,7 +85,8 @@ def get_clipper(self) -> list[str]:

return get_clipper()

def get_speaker(self, query: str) -> list[str]:
@staticmethod
def get_speaker(query: str) -> list[str]:
"""Get speaker.
:param query:
Expand All @@ -94,7 +97,8 @@ def get_speaker(self, query: str) -> list[str]:

return get_speaker(query)

def get_prompt(self, text: str, tl: str, sl: str, translators: str) -> str:
@staticmethod
def get_prompt(text: str, tl: str, sl: str, translators: str) -> str:
"""Get prompt.
:param text:
Expand All @@ -111,7 +115,8 @@ def get_prompt(self, text: str, tl: str, sl: str, translators: str) -> str:

return get_prompt(text, tl, sl, translators)

def get_youdaozhiyun_app_info(self) -> tuple[str, str]:
@staticmethod
def get_youdaozhiyun_app_info() -> tuple[str, str]:
"""Get youdaozhiyun app info.
:rtype: tuple[str, str]
Expand All @@ -120,7 +125,8 @@ def get_youdaozhiyun_app_info(self) -> tuple[str, str]:

return get_youdaozhiyun_app_info()

def complete(self, text: str, state: int) -> str:
@staticmethod
def complete(text: str, state: int) -> str:
"""Complete.
:param text:
Expand Down
3 changes: 2 additions & 1 deletion src/translate_shell/external/keyring/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
class _Keyring:
"""Keyring."""

def get_password(self, *args: str) -> str:
@staticmethod
def get_password(*args: str) -> str:
"""Get password.
:param args:
Expand Down
3 changes: 2 additions & 1 deletion src/translate_shell/external/pynotifier/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def __init__(self, *args: Any) -> None:
"""
pass

def send(self) -> None:
@staticmethod
def send() -> None:
"""Send.
:rtype: None
Expand Down
3 changes: 2 additions & 1 deletion src/translate_shell/external/pystardict/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def __init__(self, path: str) -> None:
"""
_logger.error("Please install pyyaml firstly!")

def get(self, text: str) -> str:
@staticmethod
def get(text: str) -> str:
"""Get.
:param text:
Expand Down
6 changes: 4 additions & 2 deletions src/translate_shell/translators/online/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def http_post(
"""
return self.request(url, data, True, header)

def md5sum(self, text: str | bytes) -> str:
@staticmethod
def md5sum(text: str | bytes) -> str:
"""Md5sum.
:param text:
Expand All @@ -129,7 +130,8 @@ def md5sum(self, text: str | bytes) -> str:
m.update(text)
return m.hexdigest()

def html_unescape(self, text: str) -> str:
@staticmethod
def html_unescape(text: str) -> str:
"""Html unescape.
:param text:
Expand Down
12 changes: 8 additions & 4 deletions src/translate_shell/translators/online/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def __call__(self, text: str, tl: str, sl: str) -> TRANSLATION | None:
res["alternatives"] = self.get_alternatives(obj)
return res

def get_phonetic(self, obj: list[Any]) -> str:
@staticmethod
def get_phonetic(obj: list[Any]) -> str:
"""Get phonetic.
:param obj:
Expand All @@ -82,7 +83,8 @@ def get_phonetic(self, obj: list[Any]) -> str:
return x[3]
return ""

def get_paraphrase(self, obj: list[Any]) -> str:
@staticmethod
def get_paraphrase(obj: list[Any]) -> str:
"""Get paraphrase.
:param obj:
Expand All @@ -95,7 +97,8 @@ def get_paraphrase(self, obj: list[Any]) -> str:
paraphrase += x[0]
return paraphrase

def get_explains(self, obj: list[Any]) -> dict[str, str]:
@staticmethod
def get_explains(obj: list[Any]) -> dict[str, str]:
"""Get explains.
:param obj:
Expand All @@ -110,7 +113,8 @@ def get_explains(self, obj: list[Any]) -> dict[str, str]:
expls[x[0][0]] += i[0] + "; "
return expls

def get_details(self, resp: list[Any]) -> dict[str, dict[str, str]]:
@staticmethod
def get_details(resp: list[Any]) -> dict[str, dict[str, str]]:
"""Get details.
:param resp:
Expand Down
9 changes: 6 additions & 3 deletions src/translate_shell/translators/online/haici.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def __call__(self, text: str, tl: str, sl: str) -> TRANSLATION | None:
res["details"] = self.get_details(resp)
return res

def get_phonetic(self, html: str) -> str:
@staticmethod
def get_phonetic(html: str) -> str:
"""Get phonetic.
:param html:
Expand All @@ -56,7 +57,8 @@ def get_phonetic(self, html: str) -> str:
m = re.findall(r"<span class='p'> \[(.*?)\]</span>", html)
return m[0] if m else ""

def get_explains(self, html: str) -> dict[str, str]:
@staticmethod
def get_explains(html: str) -> dict[str, str]:
"""Get explains.
:param html:
Expand All @@ -71,7 +73,8 @@ def get_explains(self, html: str) -> dict[str, str]:
explains[k + dot] = v
return explains

def get_details(self, html: str) -> dict[str, dict[str, str]]:
@staticmethod
def get_details(html: str) -> dict[str, dict[str, str]]:
"""Get details.
:param html:
Expand Down
3 changes: 2 additions & 1 deletion src/translate_shell/translators/stardict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def __call__(self, text: str, tl: str, sl: str) -> TRANSLATION | None:
res = parse_tokens(tokens, res)
return res

def get_tokens(self, text: str, tl: str, sl: str) -> tuple[list[str], str]:
@staticmethod
def get_tokens(text: str, tl: str, sl: str) -> tuple[list[str], str]:
"""Get tokens.
:param text:
Expand Down
6 changes: 4 additions & 2 deletions tests/cmd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
class Test:
"""Test."""

def test_help(self, capsys):
@staticmethod
def test_help(capsys):
"""Test help.
:param capsys:
Expand All @@ -29,7 +30,8 @@ def test_help(self, capsys):
captured = capsys.readouterr()
assert captured.out.strip() == HELP

def test_version(self, capsys):
@staticmethod
def test_version(capsys):
"""Test version.
:param capsys:
Expand Down

0 comments on commit 7c6c971

Please sign in to comment.