Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pypinyin/style/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ def get_finals(pinyin, strict):
if not finals and not strict:
return pinyin

# ńg(嗯 等)会被切出声母 n,剩下的 'g' 不是有效韵母,
# 非严格模式下应将整个 ng 作为韵母返回。
Comment on lines +63 to +64

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Replace the fullwidth punctuation in this new comment.

Lines 63-64 use fullwidth , , and , which Ruff reports as RUF003. Please normalize them to ASCII so this change stays lint-clean.

🧰 Tools
🪛 Ruff (0.15.20)

[warning] 63-63: Comment contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean ( (LEFT PARENTHESIS)?

(RUF003)


[warning] 63-63: Comment contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean ) (RIGHT PARENTHESIS)?

(RUF003)


[warning] 63-63: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF003)


[warning] 63-63: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF003)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pypinyin/style/_utils.py` around lines 63 - 64, The new comment in the helper
around pinyin splitting uses fullwidth punctuation that triggers Ruff RUF003;
update the comment in the _utils.py logic near the handling of “ńg/嗯” to use
ASCII punctuation only, replacing the fullwidth parentheses and comma with
standard ASCII equivalents while keeping the meaning unchanged.

Source: Linters/SAST tools

if not strict and pinyin == 'ng':
return pinyin

return finals


Expand Down
23 changes: 23 additions & 0 deletions tests/contrib/test_tone_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,18 @@ def test_to_initials(pinyin, strict, result):

['gui', True, False, 'uei'],
['gui', False, False, 'ui'],

# 嗯/呣/唔 等鼻音节:非严格模式下整个 m/n/ng 作为韵母,
# 严格模式下没有韵母(保持原有设计)。
Comment on lines +292 to +293

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Normalize the punctuation in the added test comments.

Lines 292-293 and Line 300 contain fullwidth punctuation that Ruff flags as RUF003. Swapping those marks to ASCII avoids a needless lint failure here.

Also applies to: 300-300

🧰 Tools
🪛 Ruff (0.15.20)

[warning] 292-292: Comment contains ambiguous (FULLWIDTH COLON). Did you mean : (COLON)?

(RUF003)


[warning] 292-292: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF003)


[warning] 293-293: Comment contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean ( (LEFT PARENTHESIS)?

(RUF003)


[warning] 293-293: Comment contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean ) (RIGHT PARENTHESIS)?

(RUF003)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/contrib/test_tone_convert.py` around lines 292 - 293, Normalize the
added test comment punctuation in test_tone_convert so Ruff no longer flags
RUF003; update the comment text around the nasal-syllable note and the later
note at the referenced spot to use ASCII punctuation instead of fullwidth marks,
keeping the same meaning while matching the project's linting rules.

Source: Linters/SAST tools

['ńg', False, False, 'ng'],
['ňg', False, False, 'ng'],
['ǹg', False, False, 'ng'],
['ng', False, False, 'ng'],
['ńg', True, False, ''],
['ng', True, False, ''],
# 控制项:单独的 m/n 行为保持不变。
['ń', False, False, 'n'],
['ḿ', False, False, 'm'],
])
def test_to_finals(pinyin, strict, v_to_u, result):
assert to_finals(pinyin, strict=strict, v_to_u=v_to_u) == result
Expand All @@ -301,6 +313,9 @@ def test_to_finals(pinyin, strict, v_to_u, result):
['yū', True, 'ǖ'],
['yu1', True, 'ǖ'],
['yū', False, 'ū'],

['ńg', False, 'ńg'],
['ńg', True, ''],
])
def test_to_finals_tone(pinyin, strict, result):
assert to_finals_tone(pinyin, strict=strict) == result
Expand All @@ -317,6 +332,9 @@ def test_to_finals_tone(pinyin, strict, result):
['yū', True, True, False, 'ü1'],
['yū', False, False, False, 'u1'],
['yū', False, True, False, 'u1'],

['ńg', False, False, False, 'n2g'],
['ńg', True, False, False, ''],
])
def test_to_finals_tone2(pinyin, strict, v_to_u,
neutral_tone_with_five, result):
Expand All @@ -336,6 +354,11 @@ def test_to_finals_tone2(pinyin, strict, v_to_u,
['yū', True, True, False, 'ü1'],
['yū', False, False, False, 'u1'],
['yū', False, True, False, 'u1'],

['ńg', False, False, False, 'ng2'],
['ňg', False, False, False, 'ng3'],
['ǹg', False, False, False, 'ng4'],
['ńg', True, False, False, ''],
])
def test_to_finals_tone3(pinyin, strict, v_to_u, neutral_tone_with_five,
result):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_others.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ def test_issue_284(neutral_tone_with_five):
neutral_tone_with_five=neutral_tone_with_five) == ['']


def test_finals_syllabic_ng_keeps_n():
# 嗯 等字的 ńg/ňg/ǹg 读音在非严格模式下,韵母应是完整的 ``ng``,
# 而不是把声母 n 切掉后剩下的无效韵母 ``g``。
Comment on lines +77 to +78

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use ASCII punctuation in these new comments.

Lines 77-78 and Line 88 introduce fullwidth punctuation that Ruff reports as RUF003. Please normalize those characters so the test file remains lint-clean.

Also applies to: 88-88

🧰 Tools
🪛 Ruff (0.15.20)

[warning] 77-77: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF003)


[warning] 77-77: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF003)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_others.py` around lines 77 - 78, Normalize the new test comments
in test_others.py to use ASCII punctuation only, since Ruff flags the fullwidth
characters as RUF003. Update the affected comment text around the assertions in
the test module so the same meaning remains but all punctuation is ASCII, and
check the nearby comment referenced by the same review to keep the file
lint-clean.

Source: Linters/SAST tools

finals = pinyin('嗯', style=Style.FINALS, heteronym=True, strict=False)[0]
assert 'ng' in finals
assert 'g' not in finals

tone3 = pinyin('嗯', style=Style.FINALS_TONE3, heteronym=True,
strict=False)[0]
assert 'ng2' in tone3 and 'ng3' in tone3 and 'ng4' in tone3
assert 'g2' not in tone3

# 严格模式(默认)下没有韵母的设计保持不变。
assert pinyin('嗯', style=Style.FINALS, heteronym=True) == [['']]


if __name__ == '__main__':
import pytest
pytest.cmdline.main()