python / python/cpython

re.sub() repl notation explanation is disjointed

Ouverte
#144,884 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

docs topic-regex
Langage dominant
Python
Étoiles
77.2k
Forks
35.9k
Métriques de merge des PR
Métriques de PR en attente

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Lisez les sections de la documentation de re.sub() et re.Match.expand() liées dans l’issue, puis comparez les paragraphes décrivant les arguments repl de type string et callable, les escapes et les flags. Le travail est terminé lorsque les détails de la notation repl et les limitations des escapes sont présentés de manière cohérente, avec la dépendance à pattern/flags placée au bon endroit ; vérifiez gh-144891 avant de commencer.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
documentation
Type d'issue
Documentation
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.