Skip to content

Commit 4372f6a

Browse files
himself65richardlau
authored andcommitted
tools: remove deprecated python api
PR-URL: #49731 Fixes: #49729 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 2e65389 commit 4372f6a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

tools/cpplint.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import math # for log
5555
import os
5656
import re
57-
import sre_compile
5857
import string
5958
import sys
6059
import sysconfig
@@ -66,6 +65,16 @@
6665

6766
__VERSION__ = '1.6.1'
6867

68+
# sre_compile will be/has been removed in Python 3.13
69+
# use re._compiler instead
70+
# Refs: https://github.com/python/cpython/issues/105456
71+
# Refs: https://github.com/python/cpython/issues/91308
72+
try:
73+
srecompile = re._compiler.compile
74+
except AttributeError:
75+
import sre_compile
76+
srecompile = sre_compile.compile
77+
6978
try:
7079
# -- pylint: disable=used-before-assignment
7180
xrange # Python 2
@@ -1077,7 +1086,7 @@ def Match(pattern, s):
10771086
# performance reasons; factoring it out into a separate function turns out
10781087
# to be noticeably expensive.
10791088
if pattern not in _regexp_compile_cache:
1080-
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
1089+
_regexp_compile_cache[pattern] = srecompile(pattern)
10811090
return _regexp_compile_cache[pattern].match(s)
10821091

10831092

@@ -1095,14 +1104,14 @@ def ReplaceAll(pattern, rep, s):
10951104
string with replacements made (or original string if no replacements)
10961105
"""
10971106
if pattern not in _regexp_compile_cache:
1098-
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
1107+
_regexp_compile_cache[pattern] = srecompile(pattern)
10991108
return _regexp_compile_cache[pattern].sub(rep, s)
11001109

11011110

11021111
def Search(pattern, s):
11031112
"""Searches the string for the pattern, caching the compiled regexp."""
11041113
if pattern not in _regexp_compile_cache:
1105-
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
1114+
_regexp_compile_cache[pattern] = srecompile(pattern)
11061115
return _regexp_compile_cache[pattern].search(s)
11071116

11081117

0 commit comments

Comments
 (0)