python / python/cpython

Deprecate re.LOCALE

オープン
#153,177 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib topic-regex type-feature
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、CPython が re.LOCALE フラグとインライン (?L) 修飾子をどのようにコンパイルするかを追跡し、次に gh-153178 を調べて、すでに進行中の作業を確認します。いずれかの形式のコンパイルで DeprecationWarning が発生し、指定された削除のタイムラインと、削除までの既存の動作が維持されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。