python / python/cpython

Refactor - remove re._compile?

Open
#122,358 5 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:

Here is re.compile:

>>> import re, inspect
>>> print(inspect.getsource(re.compile))
def compile(pattern, flags=0):
    "Compile a regular expression pattern, returning a Pattern object."
    return _compile(pattern, flags)

It just calls re._compile with the same arguments.

When it was introduced it looked like there was some benefit to having an "implementation hook" to swap in impl from sre_compile.py.

I think the benefit doesn't really exist anymore - it seems like there should be a slight performance improvement, and simpler tracebacks, to just move the body of _compile directly into compile.

Linked PRs
  • gh-122357

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 in Lib/re/init.py, examining re.compile and re._compile and the linked work in gh-122357. Determine whether the implementation hook can be removed without changing behavior; done means the redundant indirection is gone and the regular-expression module remains functional.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 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.