From c1715e04968baf46046165753c83122353b9d3de Mon Sep 17 00:00:00 2001 From: Stuart Archibald Date: Fri, 1 Dec 2023 18:22:57 +0000 Subject: [PATCH] Fix Syntax and Deprecation Warnings from 3.12. Python 3.12 highlighted a few Syntax and Deprecation warnings. This updates the code base to fix the issues highlighted (mostly use of raw strings for regex and `ast.Constant` to replace `ast.Num`). --- numba/np/ufunc/array_exprs.py | 2 +- numba/tests/test_dictobject.py | 2 +- numba/tests/test_parfors.py | 6 +++--- numba/tests/test_svml.py | 2 +- numba/tests/test_typingerror.py | 2 +- numba/tests/test_withlifting.py | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/numba/np/ufunc/array_exprs.py b/numba/np/ufunc/array_exprs.py index 458c06e636d..91fceaacf40 100644 --- a/numba/np/ufunc/array_exprs.py +++ b/numba/np/ufunc/array_exprs.py @@ -298,7 +298,7 @@ def _arr_expr_to_ast(expr): lineno=expr.loc.line, col_offset=expr.loc.col if expr.loc.col else 0), {} elif isinstance(expr, ir.Const): - return ast.Num(expr.value), {} + return ast.Constant(expr.value), {} raise NotImplementedError( "Don't know how to translate array expression '%r'" % (expr,)) diff --git a/numba/tests/test_dictobject.py b/numba/tests/test_dictobject.py index 2ad84b61356..6b91bfeb33c 100644 --- a/numba/tests/test_dictobject.py +++ b/numba/tests/test_dictobject.py @@ -1303,7 +1303,7 @@ def test_exception_nargs(self): Dict(1, 2) def test_exception_mapping_ctor(self): - msg = '.*dict\(mapping\) is not supported.*' # noqa: W605 + msg = r'.*dict\(mapping\) is not supported.*' # noqa: W605 with self.assertRaisesRegex(TypingError, msg): Dict({1: 2}) diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py index daf556a8972..0ce8beda18b 100644 --- a/numba/tests/test_parfors.py +++ b/numba/tests/test_parfors.py @@ -4131,9 +4131,9 @@ def test_impl(): cres = self.compile_parallel_fastmath(pfunc, ()) ir = self._get_gufunc_ir(cres) _id = '%[A-Z_0-9]?(.[0-9]+)+[.]?[i]?' - recipr_str = '\s+%s = fmul fast double %s, 5.000000e-01' + recipr_str = r'\s+%s = fmul fast double %s, 5.000000e-01' reciprocal_inst = re.compile(recipr_str % (_id, _id)) - fadd_inst = re.compile('\s+%s = fadd fast double %s, %s' + fadd_inst = re.compile(r'\s+%s = fadd fast double %s, %s' % (_id, _id, _id)) # check there is something like: # %.329 = fmul fast double %.325, 5.000000e-01 @@ -4582,7 +4582,7 @@ def get_gufunc_asm(self, func, schedule_type, *args, **kwargs): asm = self._get_gufunc_asm(cres) if assertions: - schedty = re.compile('call\s+\w+\*\s+@do_scheduling_(\w+)\(') + schedty = re.compile(r'call\s+\w+\*\s+@do_scheduling_(\w+)\(') matches = schedty.findall(cres.library.get_llvm_str()) self.assertGreaterEqual(len(matches), 1) # at least 1 parfor call self.assertEqual(matches[0], schedule_type) diff --git a/numba/tests/test_svml.py b/numba/tests/test_svml.py index 327de2938e8..4a5b54b3176 100644 --- a/numba/tests/test_svml.py +++ b/numba/tests/test_svml.py @@ -171,7 +171,7 @@ class TestSVMLGeneration(TestCase): # env mutating, must not run in parallel _numba_parallel_test_ = False # RE for a generic symbol reference and for each particular SVML function - asm_filter = re.compile('|'.join(['\$[a-z_]\w+,']+list(svml_funcs))) + asm_filter = re.compile('|'.join([r'\$[a-z_]\w+,']+list(svml_funcs))) @classmethod def mp_runner(cls, testname, outqueue): diff --git a/numba/tests/test_typingerror.py b/numba/tests/test_typingerror.py index 157beeb24f0..bed351a5393 100644 --- a/numba/tests/test_typingerror.py +++ b/numba/tests/test_typingerror.py @@ -207,7 +207,7 @@ def test_unsupported_type(self): cfunc(1, foo, 1) expected=re.compile(("This error may have been caused by the following " - "argument\(s\):\\n- argument 1:.*Cannot determine " + r"argument\(s\):\n- argument 1:.*Cannot determine " "Numba type of " "")) self.assertTrue(expected.search(str(raises.exception)) is not None) diff --git a/numba/tests/test_withlifting.py b/numba/tests/test_withlifting.py index b40ef11aa04..64dc178c76f 100644 --- a/numba/tests/test_withlifting.py +++ b/numba/tests/test_withlifting.py @@ -548,7 +548,7 @@ def foo(x): njit(foo)(123) # Check that an error occurred in with-lifting in objmode pat = ("During: resolving callee type: " - "type\(ObjModeLiftedWith\(<.*>\)\)") + r"type\(ObjModeLiftedWith\(<.*>\)\)") self.assertRegex(str(raises.exception), pat) def test_case07_mystery_key_error(self): @@ -822,7 +822,7 @@ def global_var(): with self.assertRaisesRegex( errors.CompilerError, ("Error handling objmode argument 'val'. " - "Global 'gv_type2' is not defined\.") + r"Global 'gv_type2' is not defined.") ): global_var()