Skip to content

Commit

Permalink
Skip re pkg frames in warnings
Browse files Browse the repository at this point in the history
This uses the warnings feature skip_file_prefixes added in 3.12
python#100840
  • Loading branch information
wimglenn committed Aug 13, 2024
1 parent df79dd5 commit 2581e10
Showing 1 changed file with 6 additions and 3 deletions.
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

0 comments on commit 2581e10

Please sign in to comment.