Skip to content

Commit be43a48

Browse files
authored
Implement input validation for nighit function
Added type checks and string handling for inputs.
1 parent 087fafd commit be43a48

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

pythainlp/morpheme/word_formation.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ def nighit(w1: str, w2: str) -> str:
3131
assert nighit("สํ","ปทา")=="สัมปทา"
3232
assert nighit("สํ","โยค")=="สังโยค"
3333
"""
34+
if not isinstance(w1, str) or not isinstance(w2, str):
35+
raise TypeError("Both w1 and w2 must be strings.")
36+
w1 = w1.strip()
37+
w2 = w2.strip()
38+
if not w1:
39+
return w2
40+
if not w2:
41+
return w1
3442
if not str(w1).endswith("ํ") and len(w1) != 2:
3543
raise NotImplementedError(f"The function doesn't support {w1}.")
3644
list_w1 = list(w1)

0 commit comments

Comments
 (0)