From a5aaf5bc343e1371e36a968856f9cad07ad357f8 Mon Sep 17 00:00:00 2001 From: Michael Achenbach Date: Tue, 16 Jan 2024 20:28:15 +0000 Subject: [PATCH] Remove deprecated sre_compile from cpplint This uses `re` instead, which should have similar performance with python3. Bug: 1517826 Change-Id: If03f386d26590dcae7da6b4f27ec1ea4926065fa Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5197707 Reviewed-by: Scott Lee Commit-Queue: Michael Achenbach Reviewed-by: Brian Ryner --- cpplint.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/cpplint.py b/cpplint.py index e448a46de1..32483eae35 100755 --- a/cpplint.py +++ b/cpplint.py @@ -52,11 +52,6 @@ import string import sys import unicodedata -# FIXME(https://crbug.com/1517826): Replace deprecated import of sre_compile. -import warnings -with warnings.catch_warnings(): - warnings.filterwarnings("ignore", category=DeprecationWarning) - import sre_compile _USAGE = r""" Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...] @@ -860,7 +855,7 @@ def Match(pattern, s): # performance reasons; factoring it out into a separate function turns out # to be noticeably expensive. if pattern not in _regexp_compile_cache: - _regexp_compile_cache[pattern] = sre_compile.compile(pattern) + _regexp_compile_cache[pattern] = re.compile(pattern) return _regexp_compile_cache[pattern].match(s) @@ -878,14 +873,14 @@ def ReplaceAll(pattern, rep, s): string with replacements made (or original string if no replacements) """ if pattern not in _regexp_compile_cache: - _regexp_compile_cache[pattern] = sre_compile.compile(pattern) + _regexp_compile_cache[pattern] = re.compile(pattern) return _regexp_compile_cache[pattern].sub(rep, s) def Search(pattern, s): """Searches the string for the pattern, caching the compiled regexp.""" if pattern not in _regexp_compile_cache: - _regexp_compile_cache[pattern] = sre_compile.compile(pattern) + _regexp_compile_cache[pattern] = re.compile(pattern) return _regexp_compile_cache[pattern].search(s)