python / python/cpython

`re` docs never say that the ASCII flag affects `\p{...}` properties

Offen
#157,698 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

docs
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Documentation

https://docs.python.org/dev/library/re.html#re.A

The re.ASCII entry lists \w, \W, \b, \B, \d, \D, \s and \S as the constructs it restricts, and the \p{property=value} section never mentions the flags. Six accepted property spellings are restricted by the flag as well, because Nd, digit, word, space, White_Space and WSpace are matched with the same engine categories as \d, \s and \w. The other 52 accepted spellings are unaffected.

$ cat repro.py
import re
s = '0\u0663 \xa0x'
for p in 'Nd', 'digit', 'word', 'space', 'White_Space', 'WSpace':
    pat = r'\p{%s}' % p
    print('%-12s %-18r %r' % (p, re.findall(pat, s), re.findall(pat, s, re.ASCII)))

$ ./python repro.py
Nd           ['0', '٣']         ['0']
digit        ['0', '٣']         ['0']
word         ['0', '٣', 'x']    ['0', 'x']
space        [' ', '\xa0']      [' ']
White_Space  [' ', '\xa0']      [' ']
WSpace       [' ', '\xa0']      [' ']

Expected: the \p{property=value} section says which properties the ASCII flag restricts, alongside the existing note that space follows str.isspace and xdigit matches only the ASCII hexadecimal digits.

\p{White_Space} and \p{WSpace} are also absent from the documented list of supported properties, although both are accepted.

Linked PRs
  • gh-157699

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der Dokumentation zu re.ASCII unter docs.python.org/dev/library/re.html#re.A, und lies anschließend den Abschnitt zu \p{property=value} sowie die Liste der unterstützten Eigenschaften. Dokumentiere, welche sechs Eigenschaftsschreibweisen durch ASCII eingeschränkt werden, und füge White_Space und WSpace zur Liste der unterstützten Eigenschaften hinzu, wobei die bestehenden Hinweise zu space und xdigit erhalten bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
documentation
Issue-Typ
Dokumentation
Schwierigkeit
1/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.