Skip to content

Commit fd10e1a

Browse files
committed
cpplint: Fix DeprecationWarning: module 'sre_compile' is deprecated
Same fix as nodejs/node#49731 tools: remove deprecated python api
1 parent 8cfc337 commit fd10e1a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

cpplint.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,19 @@
4747
import math # for log
4848
import os
4949
import re
50-
import sre_compile
5150
import string
5251
import sys
5352
import unicodedata
5453

54+
# sre_compile will be/has been removed in Python 3.13
55+
# use re._compiler instead
56+
# Refs: https://github.com/python/cpython/issues/105456
57+
# Refs: https://github.com/python/cpython/issues/91308
58+
try:
59+
srecompile = re._compiler.compile
60+
except AttributeError:
61+
import sre_compile
62+
srecompile = sre_compile.compile
5563

5664
try:
5765
xrange(0,1)
@@ -506,7 +514,7 @@ def Match(pattern, s):
506514
# performance reasons; factoring it out into a separate function turns out
507515
# to be noticeably expensive.
508516
if pattern not in _regexp_compile_cache:
509-
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
517+
_regexp_compile_cache[pattern] = srecompile(pattern)
510518
return _regexp_compile_cache[pattern].match(s)
511519

512520

@@ -524,14 +532,14 @@ def ReplaceAll(pattern, rep, s):
524532
string with replacements made (or original string if no replacements)
525533
"""
526534
if pattern not in _regexp_compile_cache:
527-
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
535+
_regexp_compile_cache[pattern] = srecompile(pattern)
528536
return _regexp_compile_cache[pattern].sub(rep, s)
529537

530538

531539
def Search(pattern, s):
532540
"""Searches the string for the pattern, caching the compiled regexp."""
533541
if pattern not in _regexp_compile_cache:
534-
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
542+
_regexp_compile_cache[pattern] = srecompile(pattern)
535543
return _regexp_compile_cache[pattern].search(s)
536544

537545

0 commit comments

Comments
 (0)