Package: numba / 0.56.4+dfsg-2

python3.11/0055-Fix-arrayexprs-for-py3.11.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
From 41585139a1fc96f5342a846d12a23920b2c0ee5d Mon Sep 17 00:00:00 2001
Origin: https://github.com/numba/numba/pull/8590
From: Siu Kwan Lam <1929845+sklam@users.noreply.github.com>
Date: Wed, 9 Nov 2022 14:49:25 -0600
Subject: [PATCH 01/14] Fix arrayexprs for py3.11 - fixes all of
 numba.tests.test_array_exprs - fixes some of numba.tests.test_parfors

---
 numba/np/ufunc/array_exprs.py | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/numba/np/ufunc/array_exprs.py b/numba/np/ufunc/array_exprs.py
index bb8815ddc42..458c06e636d 100644
--- a/numba/np/ufunc/array_exprs.py
+++ b/numba/np/ufunc/array_exprs.py
@@ -329,6 +329,28 @@ def _legalize_parameter_names(var_list):
             var.name = old_name
 
 
+class _EraseInvalidLineRanges(ast.NodeTransformer):
+    def generic_visit(self, node: ast.AST) -> ast.AST:
+        node = super().generic_visit(node)
+        if hasattr(node, "lineno"):
+            if getattr(node, "end_lineno", None) is not None:
+                if node.lineno > node.end_lineno:
+                    del node.lineno
+                    del node.end_lineno
+        return node
+
+
+def _fix_invalid_lineno_ranges(astree: ast.AST):
+    """Inplace fixes invalid lineno ranges.
+    """
+    # Make sure lineno and end_lineno are present
+    ast.fix_missing_locations(astree)
+    # Delete invalid lineno ranges
+    _EraseInvalidLineRanges().visit(astree)
+    # Make sure lineno and end_lineno are present
+    ast.fix_missing_locations(astree)
+
+
 def _lower_array_expr(lowerer, expr):
     '''Lower an array expression built by RewriteArrayExprs.
     '''
@@ -354,7 +376,7 @@ def _lower_array_expr(lowerer, expr):
         ast_fn = ast_module.body[0]
         ast_fn.args.args = ast_args
         ast_fn.body[0].value, namespace = _arr_expr_to_ast(expr.expr)
-        ast.fix_missing_locations(ast_module)
+        _fix_invalid_lineno_ranges(ast_module)
 
     # 2. Compile the AST module and extract the Python function.
     code_obj = compile(ast_module, expr_filename, 'exec')