-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
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
\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
Metadata
Metadata
Assignees
Labels
Projects
Status