python / python/cpython

re.sub() repl notation explanation is disjointed

Aperta
#144,884 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

docs topic-regex
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Leggi le sezioni della documentazione di re.sub() e re.Match.expand() collegate nell’issue, quindi confronta i paragrafi che descrivono gli argomenti repl di tipo string e callable, gli escapes e i flags. Il lavoro è completato quando i dettagli della notazione repl e le limitazioni degli escapes sono presentati in modo coerente, con la dipendenza da pattern/flags collocata nel punto appropriato; controlla gh-144891 prima di iniziare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
documentation
Tipo di issue
Documentazione
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.