Diacritics are not considered part of words

未关闭
#101,421 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
python
领域
backend

调研方向

报告提供了使用 Python re 和 unicodedata 的复现,但没有指出任何 CPython 文件或测试。首先定位 regex engine 中对 \w 的 Unicode 处理,并检查相关测试;在就分解形式的变音符号的行为达成一致并添加 regression test 后,即视为完成。

由索引模型根据 Issue 内容生成。

描述

stdlib topic-regex topic-unicode type-bug

I'm not sure whether it's a bug or expected behaviour, but it seems odd so I figure reporting it is a good idea: while a precomposed character is considered "a word" by the regex engine (specifically \w), its decomposed form is not, because a diacritic is not considered part of a word.

>>> import re, unicodedata
>>> s = "ö"
>>> list(s)
['ö']
>>> list(unicodedata.normalize('NFD', s))
['o', '̈']
>>> re.fullmatch(r'\w+', s)
<re.Match object; span=(0, 1), match='ö'>
>>> re.fullmatch(r'\w+', unicodedata.normalize('NFD', s))

This leads to odd effects when ingesting and filtering decomposed data.

Tested on 3.8.13, 3.10.6, and 3.11.1 (all installed via pyenv), on a Mint 21.1).

主要语言
Python
星标
77.2k
派生
36k
平均合并
1 天 9 小时
30 天内合并 PR
558

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

python/cpython 的其他 Issue

查看 python/cpython 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。