10000 gh-122358: Remove re._compile by wimglenn · Pull Request #122357 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-122358: Remove re._compile #122357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Skip re pkg frames in warnings
This uses the warnings feature skip_file_prefixes added in 3.12
#100840
  • Loading branch information
wimglenn committed Aug 13, 2024
commit 2581e10b68f24c5602d2835f5f5d27628e899c2e
9 changes: 6 additions & 3 deletions Lib/re/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# XXX: show string offset and offending character for all errors

import os
from ._constants import *

SPECIAL_CHARS = ".\\[{()*+?^$|"
Expand Down Expand Up @@ -508,6 +509,8 @@ def _parse_sub(source, state, verbose, nested):
subpattern.append((BRANCH, (None, items)))
return subpattern

_warn_skips = (os.path.dirname(__file__),)

def _parse(source, state, verbose, nested, first=False):
# parse a simple pattern
subpattern = SubPattern(state)
Expand Down Expand Up @@ -557,7 +560,7 @@ def _parse(source, state, verbose, nested, first=False):
import warnings
warnings.warn(
'Possible nested set at position %d' % source.tell(),
FutureWarning, stacklevel=nested + 5
FutureWarning, skip_file_prefixes=_warn_skips
)
negate = sourcematch("^")
# check remaining characters
Expand All @@ -580,7 +583,7 @@ def _parse(source, state, verbose, nested, first=False):
'symmetric difference' if this == '~' else
'union',
source.tell() - 1),
FutureWarning, stacklevel=nested + 5
FutureWarning, skip_file_prefixes=_warn_skips
)
code1 = LITERAL, _ord(this)
if sourcematch("-"):
Expand All @@ -603,7 +606,7 @@ def _parse(source, state, verbose, nested, first=False):
warnings.warn(
'Possible set difference at position %d' % (
source.tell() - 2),
FutureWarning, stacklevel=nested + 5
FutureWarning, skip_file_prefixes=_warn_skips
)
code2 = LITERAL, _ord(that)
if code1[0] != LITERAL or code2[0] != LITERAL:
Expand Down
Loading
0