From 4372f6a5b8a0920cd8616cb1d0f640fcb3e1c79e Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Tue, 19 Sep 2023 21:08:17 -0500 Subject: [PATCH] tools: remove deprecated python api PR-URL: https://github.com/nodejs/node/pull/49731 Fixes: https://github.com/nodejs/node/issues/49729 Reviewed-By: Yagiz Nizipli Reviewed-By: Marco Ippolito Reviewed-By: Luigi Pinca --- tools/cpplint.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/cpplint.py b/tools/cpplint.py index fd0940ef2ef5cf..85732b5aa43c56 100755 --- a/tools/cpplint.py +++ b/tools/cpplint.py @@ -54,7 +54,6 @@ import math # for log import os import re -import sre_compile import string import sys import sysconfig @@ -66,6 +65,16 @@ __VERSION__ = '1.6.1' +# sre_compile will be/has been removed in Python 3.13 +# use re._compiler instead +# Refs: https://github.com/python/cpython/issues/105456 +# Refs: https://github.com/python/cpython/issues/91308 +try: + srecompile = re._compiler.compile +except AttributeError: + import sre_compile + srecompile = sre_compile.compile + try: # -- pylint: disable=used-before-assignment xrange # Python 2 @@ -1077,7 +1086,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] = srecompile(pattern) return _regexp_compile_cache[pattern].match(s) @@ -1095,14 +1104,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] = srecompile(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] = srecompile(pattern) return _regexp_compile_cache[pattern].search(s)