Skip to content

Commit

Permalink
Merge branch 'backport-_replace_tone2_style_dict_to_default' into dev…
Browse files Browse the repository at this point in the history
…elop
  • Loading branch information
mozillazg committed Jul 30, 2022
2 parents 7f83c89 + 0a59df9 commit f0594f6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pypinyin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

# 用于向后兼容,TODO: 废弃
from pypinyin.seg.simpleseg import simple_seg # noqa
from pypinyin.style._tone_convert import tone2_to_tone


# 用于向后兼容,TODO: 废弃
def _replace_tone2_style_dict_to_default(string):
return tone2_to_tone(string)


def _remove_dup_items(lst, remove_empty=False):
Expand Down
4 changes: 4 additions & 0 deletions pypinyin/utils.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from typing import List, Text


def _replace_tone2_style_dict_to_default(string: Text) -> Text: ...


def _remove_dup_items(lst: List[Text]) -> List[Text]: ...


Expand Down
8 changes: 7 additions & 1 deletion tests/contrib/test_tone_sandhi.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@ class MyConverter(ToneSandhiMixin, DefaultConverter):
# 不满足变调条件
[['之一'], ['zhi1', 'yi1'], ['zhi1', 'yi1']],
[['一'], ['yi1'], ['yi1']],
# #270
[['永远'], ['yo3ng', 'yua3n'], ['yo2ng', 'yua3n']],
[['两手'], ['lia3ng', 'sho3u'], ['lia2ng', 'sho3u']],
[['辗转反侧'], ['zha3n', 'zhua3n', 'fa3n', 'ce4'],
['zha3n', 'zhua3n', 'fa3n', 'ce4']],
])
def test_tone_sandhi(han, normal_output, sandhi_output):
assert lazy_pinyin(han, style=Style.TONE2) == normal_output or \
lazy_pinyin(han, style=Style.TONE2) == sandhi_output
lazy_pinyin(han, style=Style.TONE2) == sandhi_output

assert my_pinyin.lazy_pinyin(han, style=Style.TONE2) == sandhi_output
# 测试关键字参数
Expand Down

0 comments on commit f0594f6

Please sign in to comment.