From 32e5011b45de6bee4b479b8d591b000f508fe46c Mon Sep 17 00:00:00 2001 From: mozillazg Date: Mon, 15 Aug 2022 08:19:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E5=A3=B0=E6=AF=8D?= =?UTF-8?q?=E5=92=8C=E9=9F=B5=E6=AF=8D=E7=9A=84=E5=9C=BA=E6=99=AF=E4=B8=8B?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=20neutral=5Ftone=5Fwith=5Ffive=3DTrue=20?= =?UTF-8?q?=E4=BC=9A=E8=BF=94=E5=9B=9E=205=20=E4=BD=9C=E4=B8=BA=E6=8B=BC?= =?UTF-8?q?=E9=9F=B3=E7=9A=84=E9=97=AE=E9=A2=98=20#284?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pypinyin/contrib/neutral_tone.py | 2 ++ tests/test_others.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/pypinyin/contrib/neutral_tone.py b/pypinyin/contrib/neutral_tone.py index 49124fdb..3f0864a6 100644 --- a/pypinyin/contrib/neutral_tone.py +++ b/pypinyin/contrib/neutral_tone.py @@ -56,6 +56,8 @@ def post_convert_style(self, han, orig_pinyin, converted_pinyin, if pre_data is not None: converted_pinyin = pre_data + if not converted_pinyin: # 空字符串 + return converted_pinyin # 有声调,跳过 if _re_number.search(converted_pinyin): return converted_pinyin diff --git a/tests/test_others.py b/tests/test_others.py index 370ca330..a505e8eb 100644 --- a/tests/test_others.py +++ b/tests/test_others.py @@ -2,6 +2,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals +from pytest import mark + from pypinyin import pinyin, Style, lazy_pinyin, slug from pypinyin.seg.simpleseg import simple_seg @@ -49,6 +51,14 @@ def test_issue_266(): assert lazy_pinyin('呣', style=Style.FINALS, strict=False) == ['m'] +@mark.parametrize('neutral_tone_with_five', [True, False]) +def test_issue_284(neutral_tone_with_five): + assert lazy_pinyin('嗯', style=Style.FINALS_TONE3, + neutral_tone_with_five=neutral_tone_with_five) == [''] + assert lazy_pinyin('呣', style=Style.FINALS_TONE3, + neutral_tone_with_five=neutral_tone_with_five) == [''] + + if __name__ == '__main__': import pytest pytest.cmdline.main()