re.sub() repl notation explanation is disjointed
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Documentation
[I'm sending a PR proposing multiple changes, trying to list here the more "objective" issues and leaving my subjective choices to the PR...]
re.sub, also briefly in re.Match.expand.
Information on how repl argument is processed is split between the first (" repl can be a string or a function; if it is a string ...") and second-to-last paragraphs ("In string-type repl arguments, in addition ..."), in a way that is somewhat arbitrary/illogical, and some important subtleties are omitted:
- "Unknown escapes" are discussed in first paragraph after mentioning only regular python escapes like \n, before sentence on
\6and far before introducing\g<...>in late paragraph! \6is introduced early but details of how\20is parsed is added late in\gdiscussion. Ambiguities vs. octal notation (\02,\200,\2000) are not mentioned. Reader may guess this is like\2vs. octal in regex notation.- The wording suggests "all escapes" supported in Python string literals are processed. Not so —
\x\u\U\Naren't, UNLIKE regex notation. This bears on "unknown escape" handling.
Additionally, the final paragraph documenting flags (added in #119960) comes far after "The pattern may be a string or a Pattern", but actually flags param is only allowed when pattern pattern is a string, which can be best explained by moving these together.
[However, that dependence is worth mentioning in several other functions, so perhaps that deserves separate issue/PR?]
Linked PRs
- gh-144891
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
阅读 issue 中链接的 re.sub() 和 re.Match.expand() 文档部分,然后比较描述字符串和可调用 repl 参数、转义符以及 flags 的段落。完成标准是:repl 表示法的细节和转义限制表述连贯,并将 pattern/flags 依赖关系放在适当位置;开始前检查 gh-144891。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100