Skip to content

Commit cec1a12

Browse files
committed
dataclasses = conciseness & clean
1 parent 51d3422 commit cec1a12

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

scratchattach/other/other_apis.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ def translate(language: str | Languages, text: str = "hello"):
166166
if lang is None:
167167
raise ValueError(f"{language} is not a supported translate language")
168168

169-
print(lang.__dict__)
170169
response_json = requests.get(
171170
f"https://translate-service.scratch.mit.edu/translate?language={lang.code}&text={text}").json()
172171

scratchattach/utils/supportedlangs.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,18 @@
44
"""
55

66
from enum import Enum
7+
from dataclasses import dataclass
8+
79
from typing import Callable
810

911

12+
@dataclass(init=True, repr=True)
1013
class _Language:
11-
def __init__(self, name: str = None, code: str = None, locales: list[str] = None, tts_locale: str = None,
12-
single_gender: bool = None):
13-
self.name = name
14-
self.code = code
15-
self.locales = locales
16-
self.tts_locale = tts_locale
17-
self.single_gender = single_gender
18-
19-
def __repr__(self):
20-
ret = "Language("
21-
for attr in self.__dict__.keys():
22-
if not attr.startswith("_"):
23-
val = getattr(self, attr)
24-
ret += f"{repr(val)}, "
25-
if ret.endswith(", "):
26-
ret = ret[:-2]
27-
28-
ret += ')'
29-
return ret
30-
31-
def __str__(self):
32-
return f"Language<{self.name} - {self.code}>"
14+
name: str = None
15+
code: str = None
16+
locales: list[str] = None
17+
tts_locale: str = None
18+
single_gender: bool = None
3319

3420

3521
class Languages(Enum):

0 commit comments

Comments
 (0)