# -*- coding: utf-8 -*-
"""
Syllable tools
"""
import re
from pythainlp import thai_consonants

spelling_class = {
    "กง": list("ง"),
    "กม": list("ม"),
    "เกย": list("ย"),
    "เกอว": list("ว"),
    "กน": list("นญณรลฬ"),
    "กก": list("กขคฆ"),
    "กด": list("ดจชซฎฏฐฑฒตถทธศษส"),
    "กบ": list("บปภพฟ")
}

thai_consonants_all = list(thai_consonants)
thai_consonants_all.remove("อ")

_temp = list(
    "".join(["".join(spelling_class[i]) for i in spelling_class.keys()])
)
not_spelling_class = [j for j in thai_consonants_all if j not in _temp]

# vowel's short sound
short = "ะัิึุ"
re_short = re.compile("เ(.*)ะ|แ(.*)ะ|เ(.*)อะ|โ(.*)ะ|เ(.*)าะ", re.U)
pattern = re.compile("เ(.*)า", re.U)  # เ-า is live syllable

_check_1 = []
# these spelling consonant are live syllable.
for i in ["กง", "กน", "กม", "เกย", "เกอว"]:
    _check_1.extend(spelling_class[i])
# these spelling consonant are dead syllable.
_check_2 = spelling_class["กก"]+spelling_class["กบ"]+spelling_class["กด"]


def sound_syllable(syllable: str) -> str:
    """
    Sound syllable classification

    This function is sound syllable classification.
    It is live syllable or dead syllable.

    :param str syllable: Thai syllable
    :return: syllable's type (live or dead)
    :rtype: str

    :Example:
    ::

        from pythainlp.util import sound_syllable

        print(sound_syllable("มา"))
        # output: live

        print(sound_syllable("เลข"))
        # output: dead
    """
    syllable_type = ""
    # get consonants
    consonants = [i for i in syllable if i in list(thai_consonants_all)]
    # get spelling consonants
    spelling_consonant = consonants[-1]
    # if len of syllable < 2
    if len(syllable) < 2:
        syllable_type = "dead"
    elif (
        (
            spelling_consonant in _check_2)
            and
            (
                any((c in set("าีืแูาเโ")) for c in syllable) is False
                and any((c in set("ำใไ")) for c in syllable) is False
                and not pattern.findall(syllable) is True
            )
    ):
        syllable_type = "dead"
    elif any((c in set("าีืแูาโ")) for c in syllable):  # in syllable:
        if spelling_consonant != syllable[-1]:
            syllable_type = "live"
        elif spelling_consonant in _check_1:
            syllable_type = "live"
        elif spelling_consonant in _check_2:
            syllable_type = "dead"
        elif (
            re_short.findall(syllable)
            or
            any((c in set(short)) for c in syllable)
        ):
            syllable_type = "dead"
        syllable_type = "live"
    elif any((c in set("ำใไ")) for c in syllable):
        syllable_type = "live"  # if these vowel's long sound are live syllable
    elif pattern.findall(syllable):  # if it is เ-า
        syllable_type = "live"
    elif spelling_consonant in _check_1:
        if (
            re_short.findall(syllable)
            or
            any((c in set(short)) for c in syllable)
        ) and len(consonants) < 2:
            syllable_type = "dead"
        syllable_type = "live"
    elif (
        re_short.findall(syllable)  # if found vowel's short sound
        or
        any((c in set(short)) for c in syllable)  # consonant in short
    ):
        syllable_type = "dead"
    else:
        syllable_type = "dead"
    return syllable_type

@@ -1465,31 +1465,8 @@
 %22%22%22%0A
-    syllable_type = %22%22%0A
     
@@ -1684,39 +1684,30 @@
  2:%0A        
-syllable_type =
+return
  %22dead%22%0A    
@@ -1851,34 +1851,34 @@
  c in syllable) 
-is
+==
  False%0A         
@@ -1929,18 +1929,18 @@
 llable) 
-is
+==
  False%0A 
@@ -1958,20 +1958,16 @@
     and 
-not 
 pattern.
@@ -1984,18 +1984,18 @@
 llable) 
-is
+!=
  True%0A  
@@ -2017,39 +2017,30 @@
  ):%0A        
-syllable_type =
+return
  %22dead%22%0A    
@@ -2161,39 +2161,30 @@
             
-syllable_type =
+return
  %22live%22%0A    
@@ -2232,39 +2232,30 @@
             
-syllable_type =
+return
  %22live%22%0A    
@@ -2303,39 +2303,30 @@
             
-syllable_type =
+return
  %22dead%22%0A    
@@ -2462,39 +2462,30 @@
             
-syllable_type =
+return
  %22dead%22%0A    
@@ -2484,39 +2484,30 @@
 ad%22%0A        
-syllable_type =
+return
  %22live%22%0A    
@@ -2557,39 +2557,30 @@
 e):%0A        
-syllable_type =
+return
  %22live%22  # i
@@ -2680,39 +2680,30 @@
 %E0%B9%80-%E0%B8%B2%0A        
-syllable_type =
+return
  %22live%22%0A    
@@ -2902,39 +2902,30 @@
             
-syllable_type =
+return
  %22dead%22%0A    
@@ -2928,31 +2928,22 @@
         
-syllable_type =
+return
  %22live%22%0A
@@ -3113,39 +3113,30 @@
  ):%0A        
-syllable_type =
+return
  %22dead%22%0A    
@@ -3153,52 +3153,18 @@
     
-syllable_type = %22dead%22%0A    return syllable_type
+return %22dead%22
 %0A

Update syllable.py