python / python/cpython

Deprecate re.LOCALE

Aperta
#153,177 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

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

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

Inizia tracciando il modo in cui CPython compila il flag re.LOCALE e il modificatore inline (?L), quindi esamina gh-153178 per individuare il lavoro già in corso. Il lavoro è completo quando la compilazione di una delle due forme emette una DeprecationWarning, preservando al contempo la tempistica di rimozione indicata e il comportamento esistente fino alla rimozione.

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

Valutazione

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.