Repository: numba/numba

Issue:
`template.path` doesn't point to source code location in `overload_method`
when testing with `overload_method`, it turns out that the type template of `overload_method` has a wrong implementation in `get_source_code_info`, since the attribute `path` in it will point to `numba/core/typing/templates.py`, rather than the real source code file path which the `overload_method`-ed function is defined.

Need to give you a reproducer later..

And it's related to proceed the cache PR https://github.com/numba/numba/pull/8396, I think.


Discussion:

Resolving patch:
diff --git a/numba/core/typing/templates.py b/numba/core/typing/templates.py
--- a/numba/core/typing/templates.py
+++ b/numba/core/typing/templates.py
@@ -1143,6 +1143,22 @@ def generic(_, args, kws):
                 if sig is not None:
                     return sig.as_method()
 
+            def get_template_info(self):
+                basepath = os.path.dirname(os.path.dirname(numba.__file__))
+                impl = self._overload_func
+                code, firstlineno, path = self.get_source_code_info(impl)
+                sig = str(utils.pysignature(impl))
+                info = {
+                    'kind': "overload_method",
+                    'name': getattr(impl, '__qualname__', impl.__name__),
+                    'sig': sig,
+                    'filename': utils.safe_relpath(path, start=basepath),
+                    'lines': (firstlineno, firstlineno + len(code) - 1),
+                    'docstring': impl.__doc__
+                }
+
+                return info
+
         return types.BoundFunction(MethodTemplate, typ)
 
 


Test patch:
diff --git a/numba/tests/test_typeinfer.py b/numba/tests/test_typeinfer.py
--- a/numba/tests/test_typeinfer.py
+++ b/numba/tests/test_typeinfer.py
@@ -9,6 +9,7 @@
 from numba import jit, njit
 from numba.core import errors, ir, types, typing, typeinfer, utils
 from numba.core.typeconv import Conversion
+from numba.extending import overload_method
 
 from numba.tests.support import TestCase, tag
 from numba.tests.test_typeconv import CompatibilityTestMixin
@@ -713,6 +714,34 @@ def confuse_typer(x):
 
         self.assertTrue(all(vt == types.float64 for vt in return_vars.values()))
 
+    def test_issue_9162(self):
+        @overload_method(types.Array, "aabbcc")
+        def ol_aabbcc(self):
+
+            def impl(self):
+                return self.sum()
+
+            return impl
+
+        @jit
+        def foo(ar):
+            return ar.aabbcc()
+
+        ar = np.ones(2)
+        ret = foo(ar)
+
+        overload = [value for value in foo.overloads.values()][0]
+        typemap = overload.type_annotation.typemap
+        calltypes = overload.type_annotation.calltypes
+        for call_op in calltypes:
+            name = call_op.list_vars()[0].name
+            fc_ty = typemap[name]
+            self.assertIsInstance(fc_ty, types.BoundFunction)
+            tmplt = fc_ty.template
+            info = tmplt.get_template_info(tmplt)
+            py_file = info["filename"]
+            self.assertIn("test_typeinfer.py", py_file)
+
     @skip_unless_load_fast_and_clear
     def test_load_fast_and_clear(self):
         @njit
@@ -778,7 +807,6 @@ def foo(a):
         self.assertEqual(foo(0), 0)
 
 
-
 class TestFoldArguments(unittest.TestCase):
     def check_fold_arguments_list_inputs(self, func, args, kws):
         def make_tuple(*args):