4a228144f6
OBS-URL: https://build.opensuse.org/request/show/625840 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-numba?expand=0&rev=13
49 lines
2.0 KiB
Diff
49 lines
2.0 KiB
Diff
From 99d35798b2e833792624574fd1b31b41bd1f496e Mon Sep 17 00:00:00 2001
|
|
From: Stuart Archibald <stuart.archibald@googlemail.com>
|
|
Date: Thu, 19 Jul 2018 20:38:31 +0100
|
|
Subject: [PATCH] Fix #3135
|
|
|
|
This fixes #3135 by adding guards to make sure that only line
|
|
numbers in Z^+ are accessed and if no lines are found then they
|
|
are not addressed. Test case from bug report is added.
|
|
---
|
|
numba/ir.py | 18 ++++++++++++------
|
|
numba/tests/test_errorhandling.py | 16 ++++++++++++++++
|
|
2 files changed, 28 insertions(+), 6 deletions(-)
|
|
|
|
--- a/numba/ir.py
|
|
+++ b/numba/ir.py
|
|
@@ -63,7 +63,12 @@ class Loc(object):
|
|
spaces += 1
|
|
return spaces
|
|
|
|
- selected = lines[self.line - nlines_up:self.line]
|
|
+ # A few places in the code still use no `loc` or default to line 1
|
|
+ # this is often in places where exceptions are used for the purposes
|
|
+ # of flow control. As a result max is in use to prevent slice from
|
|
+ # `[negative: positive]`
|
|
+ selected = lines[max(0, self.line - nlines_up):self.line]
|
|
+
|
|
# see if selected contains a definition
|
|
def_found = False
|
|
for x in selected:
|
|
@@ -83,12 +88,13 @@ class Loc(object):
|
|
spaces = count_spaces(x)
|
|
ret.append(' '*(4 + spaces) + '<source elided>\n')
|
|
|
|
- ret.extend(selected[:-1])
|
|
- ret.append(_termcolor.highlight(selected[-1]))
|
|
+ if selected:
|
|
+ ret.extend(selected[:-1])
|
|
+ ret.append(_termcolor.highlight(selected[-1]))
|
|
|
|
- # point at the problem with a caret
|
|
- spaces = count_spaces(selected[-1])
|
|
- ret.append(' '*(spaces) + _termcolor.indicate("^"))
|
|
+ # point at the problem with a caret
|
|
+ spaces = count_spaces(selected[-1])
|
|
+ ret.append(' '*(spaces) + _termcolor.indicate("^"))
|
|
|
|
# if in the REPL source may not be available
|
|
if not ret:
|