python / python/cpython

Deprecate re.LOCALE

Offen
#153,177 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

stdlib topic-regex type-feature
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Feature or enhancement

Proposal:

Deprecate the re.LOCALE flag and the inline (?L) modifier: emit a DeprecationWarning when compiling a pattern that uses them, for removal no earlier than Python 3.18.

re.LOCALE only works with bytes patterns and only makes sense in 8-bit locales, which are rare today (it does not work in UTF-8 or other multibyte locales). It makes matching an order of magnitude slower: it excludes compile-time optimization of character sets, and at matching time it calls the locale-dependent C functions for every character instead of a table lookup. It also complicates the engine: every character class and case-insensitive operation needs a third variant beside the plain and Unicode ones, and every new optimization must special-case it.

A scan of the top 5,000 PyPI projects found 14 matches in 9 projects, and in the observed cases the flag was unnecessary. The replacement is to decode input and use str patterns, or to spell the needed byte semantics explicitly in the pattern.

This was discussed in 2023 in https://discuss.python.org/t/what-to-do-with-re-locale/32600 with a consensus for deprecation; matching str patterns with re.LOCALE has already been an error since Python 3.6 (bpo-22407).

Linked PRs
  • gh-153178

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 damit nachzuverfolgen, wie CPython das Flag re.LOCALE und den Inline-Modifikator (?L) kompiliert, und prüfe anschließend gh-153178 auf bereits laufende Arbeiten. Als abgeschlossen gilt die Aufgabe, wenn die Kompilierung einer der beiden Formen eine DeprecationWarning ausgibt und dabei der angegebene Zeitplan für die Entfernung sowie das bestehende Verhalten bis zur Entfernung erhalten bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
backend
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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