Skip to content

Commit

Permalink
Fix Syntax and Deprecation Warnings from 3.12.
Browse files Browse the repository at this point in the history
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`).
  • Loading branch information
stuartarchibald committed Dec 4, 2023
1 parent db5f0a4 commit c1715e0
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion numba/np/ufunc/array_exprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,))

Expand Down
2 changes: 1 addition & 1 deletion numba/tests/test_dictobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
6 changes: 3 additions & 3 deletions numba/tests/test_parfors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion numba/tests/test_svml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion numba/tests/test_typingerror.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
"<class \'numba.tests.test_typingerror.Foo\'>"))
self.assertTrue(expected.search(str(raises.exception)) is not None)
Expand Down
4 changes: 2 additions & 2 deletions numba/tests/test_withlifting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit c1715e0

Please sign in to comment.