Skip to content

Commit a5c48a0

Browse files
committed
docstrings and removing use of kwarg for all_of
1 parent cec1a12 commit a5c48a0

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

scratchattach/other/other_apis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ def translate(language: str | Languages, text: str = "hello"):
152152
lang = language
153153
if isinstance(language, str):
154154
if language.lower() in Languages.all_of("code", str.lower):
155-
lang = Languages.find(language.lower(), "code", apply_func=str.lower)
155+
lang = Languages.find(language.lower(), "code", str.lower)
156156

157157
elif language.lower() in Languages.all_of("name", str.lower):
158-
lang = Languages.find(language.lower(), apply_func=str.lower)
158+
lang = Languages.find(language.lower(), "name", str.lower)
159159

160160
elif isinstance(language, Languages):
161161
lang = language.value

scratchattach/utils/supportedlangs.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ class Languages(Enum):
9696

9797
@staticmethod
9898
def find(value, by: str = "name", apply_func: Callable = None) -> _Language:
99+
"""
100+
Finds the language with the given attribute that is equal to the given value.
101+
the apply_func will be applied to the attribute of each language object before comparison.
102+
103+
i.e. Languages.find("ukranian", "name", str.lower) will return the Ukrainian language dataclass object
104+
(even though Ukrainian was spelt lowercase, since str.lower will convert the "Ukrainian" string to lowercase)
105+
"""
99106
if apply_func is None:
100107
def apply_func(x):
101108
return x
@@ -111,6 +118,16 @@ def apply_func(x):
111118

112119
@staticmethod
113120
def all_of(attr_name: str = "name", apply_func: Callable = None):
121+
"""
122+
Returns the list of each listed language's specified attribute by "attr_name"
123+
124+
i.e. Languages.all_of("name") will return a list of names:
125+
["Albanian", "Amharic", ...]
126+
127+
The apply_func function will be applied to every list item,
128+
i.e. Languages.all_of("name", str.lower) will return the same except in lowercase:
129+
["albanian", "amharic", ...]
130+
"""
114131
if apply_func is None:
115132
def apply_func(x):
116133
return x

0 commit comments

Comments
 (0)