python / python/cpython

Deprecate re.LOCALE

Open
#153,177 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-regex type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how CPython compiles the re.LOCALE flag and inline (?L) modifier, then inspect gh-153178 for work already underway. Done means compilation of either form emits a DeprecationWarning while preserving the stated removal timeline and existing behavior until removal.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.