Skip to content

Commit 2581e10

Browse files
committed
Skip re pkg frames in warnings
This uses the warnings feature skip_file_prefixes added in 3.12 python#100840
1 parent df79dd5 commit 2581e10

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Lib/re/_parser.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

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

15+
import os
1516
from ._constants import *
1617

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

512+
_warn_skips = (os.path.dirname(__file__),)
513+
511514
def _parse(source, state, verbose, nested, first=False):
512515
# parse a simple pattern
513516
subpattern = SubPattern(state)
@@ -557,7 +560,7 @@ def _parse(source, state, verbose, nested, first=False):
557560
import warnings
558561
warnings.warn(
559562
'Possible nested set at position %d' % source.tell(),
560-
FutureWarning, stacklevel=nested + 5
563+
FutureWarning, skip_file_prefixes=_warn_skips
561564
)
562565
negate = sourcematch("^")
563566
# check remaining characters
@@ -580,7 +583,7 @@ def _parse(source, state, verbose, nested, first=False):
580583
'symmetric difference' if this == '~' else
581584
'union',
582585
source.tell() - 1),
583-
FutureWarning, stacklevel=nested + 5
586+
FutureWarning, skip_file_prefixes=_warn_skips
584587
)
585588
code1 = LITERAL, _ord(this)
586589
if sourcematch("-"):
@@ -603,7 +606,7 @@ def _parse(source, state, verbose, nested, first=False):
603606
warnings.warn(
604607
'Possible set difference at position %d' % (
605608
source.tell() - 2),
606-
FutureWarning, stacklevel=nested + 5
609+
FutureWarning, skip_file_prefixes=_warn_skips
607610
)
608611
code2 = LITERAL, _ord(that)
609612
if code1[0] != LITERAL or code2[0] != LITERAL:

0 commit comments

Comments
 (0)