Skip to content

Fix tone sandhi alignment when unknown characters are ignored - #386

Open
lanqing431 wants to merge 1 commit into
mozillazg:developfrom
lanqing431:fix/ignored-characters-tone-sandhi-20261127
Open

lanqing431 wants to merge 1 commit into
mozillazg:developfrom
lanqing431:fix/ignored-characters-tone-sandhi-20261127

Conversation

@lanqing431

Copy link
Copy Markdown

PR 描述

预分词输入同时使用 tone_sandhi=True 和 errors='ignore' 时,无拼音汉字的结果会被提前移除,但变调仍按原汉字位置索引。例如 lazy_pinyin(['鿅不对'], tone_sandhi=True, errors='ignore') 抛出 IndexError。

保留被忽略字符的空位置,完成变调和风格转换后才移除。变调在非空连续片段内处理,避免跨过被忽略的字符连读;支持 ToneSandhiMixin 和 UltimateConverter,以及返回 None/空列表的 errors 回调。不改动三声及“一”“不”的既有语言学规则。

自测

  • 新增 42 个参数组合,覆盖未知字符在首/中/尾、变调边界、全未知输入及三种忽略方式;原实现其中 36 项失败,6 项通过。
  • python -m pytest tests/ pypinyin/ --random-order:1142 passed,2 skipped,包含模块 doctest。
  • python -m mypy --strict pypinyin:45 个源码文件通过。
  • 所有配置的 pre-commit hooks 在三个修改文件上通过;git diff --check 通过。

Python 3.12.10 / Windows。启用 coverage 的运行在收集未修改的生成词库时未能完成,本次不报告覆盖率;不带 coverage 的完整测试已通过。全文件 pre-commit 另发现原有 docs/CHANGELOG.rst 缺末尾换行,该文件未纳入此修改。

本修改由 Codex 协助实现与验证。

@coderabbitai

coderabbitai Bot commented Nov 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d9c31d64-3210-45d0-a40d-1ed6c5a06505

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant