python / python/cpython

re.sub() repl notation explanation is disjointed

オープン
#144,884 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

docs topic-regex
主要言語
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 \6 and far before introducing \g<...> in late paragraph!
  • \6 is introduced early but details of how \20 is parsed is added late in \g discussion. Ambiguities vs. octal notation (\02, \200, \2000) are not mentioned. Reader may guess this is like \2 vs. octal in regex notation.
  • The wording suggests "all escapes" supported in Python string literals are processed. Not so — \x\u\U\N aren'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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

issue にリンクされている re.sub() と re.Match.expand() のドキュメントセクションを読み、string および callable の repl 引数、エスケープ、flags について説明している段落を比較します。完了条件は、repl 表記の詳細とエスケープの制限が一貫して示され、pattern/flags の依存関係が適切な位置に置かれていることです。開始前に gh-144891 を確認してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
documentation
issue の種類
ドキュメント
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。