8000 Apply some small formatting fixes in ultratb · ipython/ipython@f7014a8 · GitHub
[go: up one dir, main page]

Skip to conte 8000 nt

Commit f7014a8

Browse files
Apply some small formatting fixes in ultratb
1 parent ef994b4 commit f7014a8

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

IPython/core/tests/test_ultratb.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,24 @@ def wrapper(*args, **kwargs):
5151
class ChangedPyFileTest(unittest.TestCase):
5252
def test_changing_py_file(self):
5353
"""Traceback produced if the line where the error occurred is missing?
54-
54+
5555
https://github.com/ipython/ipython/issues/1456
5656
"""
5757
with TemporaryDirectory() as td:
5858
fname = os.path.join(td, "foo.py")
5959
with open(fname, "w", encoding="utf-8") as f:
6060
f.write(file_1)
61-
61+
6262
with prepended_to_syspath(td):
6363
ip.run_cell("import foo")
64-
64+
6565
with tt.AssertPrints("ZeroDivisionError"):
6666
ip.run_cell("foo.f()")
67-
67+
6868
# Make the file shorter, so the line of t 10000 he error is missing.
6969
with open(fname, "w", encoding="utf-8") as f:
7070
f.write(file_2)
71-
71+
7272
# For some reason, this was failing on the *second* call after
7373
# changing the file, so we call f() twice.
7474
with tt.AssertNotPrints("Internal Python error", channel='stderr'):
@@ -92,27 +92,27 @@ def test_nonascii_path(self):
9292
fname = os.path.join(td, u"fooé.py")
9393
with open(fname, "w", encoding="utf-8") as f:
9494
f.write(file_1)
95-
95+
9696
with prepended_to_syspath(td):
9797
ip.run_cell("import foo")
98-
98+
9999
with tt.AssertPrints("ZeroDivisionError"):
100100
ip.run_cell("foo.f()")
101-
101+
102102
def test_iso8859_5(self):
103103
with TemporaryDirectory() as td:
104104
fname = os.path.join(td, 'dfghjkl.py')
105105

106106
with io.open(fname, 'w', encoding='iso-8859-5') as f:
107107
f.write(iso_8859_5_file)
108-
108+
109109
with prepended_to_syspath(td):
110110
ip.run_cell("from dfghjkl import fail")
111-
111+
112112
with tt.AssertPrints("ZeroDivisionError"):
113113
with tt.AssertPrints(u'дбИЖ', suppress=False):
114114
ip.run_cell('fail()')
115-
115+
116116
def test_nonascii_msg(self):
117117
cell = u"raise Exception('é')"
118118
expected = u"Exception('é')"
@@ -167,12 +167,12 @@ def test_indentationerror_shows_line(self):
167167
with tt.AssertPrints("IndentationError"):
168168
with tt.AssertPrints("zoon()", suppress=False):
169169
ip.run_cell(indentationerror_file)
170-
170+
171171
with TemporaryDirectory() as td:
172172
fname = os.path.join(td, "foo.py")
173173
with open(fname, "w", encoding="utf-8") as f:
174174
f.write(indentationerror_file)
175-
175+
176176
with tt.AssertPrints("IndentationError"):
177177
with tt.AssertPrints("zoon()", suppress=False):
178178
ip.magic('run %s' % fname)

IPython/core/ultratb.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def _format_list(self, extracted_list):
591591
"""
592592

593593
Colors = self.Colors
594-
list = []
594+
output_list = []
595595
for ind, (filename, lineno, name, line) in enumerate(extracted_list):
596596
normalCol, nameCol, fileCol, lineCol = (
597597
# Emphasize the last entry
@@ -609,9 +609,9 @@ def _format_list(self, extracted_list):
609609
item += "\n"
610610
if line:
611611
item += f"{lineCol} {line.strip()}{normalCol}\n"
612-
list.append(item)
612+
output_list.append(item)
613613

614-
return list
614+
return output_list
615615

616616
def _format_exception_only(self, etype, value):
617617
"""Format the exception part of a traceback.
@@ -628,11 +628,11 @@ def _format_exception_only(self, etype, value):
628628
"""
629629
have_filedata = False
630630
Colors = self.Colors
631-
list = []
631+
output_list = []
632632
stype = py3compat.cast_unicode(Colors.excName + etype.__name__ + Colors.Normal)
633633
if value is None:
634634
# Not sure if this can still happen in Python 2.6 and above
635-
list.append(stype + '\n')
635+
output_list.append(stype + "\n")
636636
else:
637637
if issubclass(etype, SyntaxError):
638638
have_filedata = True
@@ -643,7 +643,7 @@ def _format_exception_only(self, etype, value):
643643
else:
644644
lineno = "unknown"
645645
textline = ""
646-
list.append(
646+
output_list.append(
647647
"%s %s%s\n"
648648
% (
649649
Colors.normalEm,
@@ -663,39 +663,41 @@ def _format_exception_only(self, etype, value):
663663
i = 0
664664
while i < len(textline) and textline[i].isspace():
665665
i += 1
666-
list.append('%s %s%s\n' % (Colors.line,
667-
textline.strip(),
668-
Colors.Normal))
666+
output_list.append(
667+
"%s %s%s\n" % (Colors.line, textline.strip(), Colors.Normal)
668+
)
669669
if value.offset is not None:
670670
s = ' '
671671
for c in textline[i:value.offset - 1]:
672672
if c.isspace():
673673
s += c
674674
else:
675-
s += ' '
676-
list.append('%s%s^%s\n' % (Colors.caret, s,
677-
Colors.Normal))
675+
s += " "
676+
output_list.append(
677+
"%s%s^%s\n" % (Colors.caret, s, Colors.Normal)
678+
)
678679

679680
try:
680681
s = value.msg
681682
except Exception:
682683
s = self._some_str(value)
683684
if s:
684-
list.append('%s%s:%s %s\n' % (stype, Colors.excName,
685-
Colors.Normal, s))
685+
output_list.append(
686+
"%s%s:%s %s\n" % (stype, Colors.excName, Colors.Normal, s)
687+
)
686688
else:
687-
list.append('%s\n' % stype)
689+
output_list.append("%s\n" % stype)
688690

689691
# PEP-678 notes
690-
list.extend(f"{x}\n" for x in getattr(value, "__notes__", []))
692+
output_list.extend(f"{x}\n" for x in getattr(value, "__notes__", []))
691693

692694
# sync with user hooks
693695
if have_filedata:
694696
ipinst = get_ipython()
695697
if ipinst is not None:
696698
ipinst.hooks.synchronize_with_editor(value.filename, value.lineno, 0)
697699

698-
return list
700+
return output_list
699701

700702
def get_exception_only(self, etype, value):
701703
"""Only print the exception type and message, without a traceback.
@@ -1012,6 +1014,7 @@ def format_exception(self, etype, evalue):
10121014
etype, evalue = str, sys.exc_info()[:2]
10131015
etype_str, evalue_str = map(str, (etype, evalue))
10141016

1017+
# PEP-678 notes
10151018
notes = getattr(evalue, "__notes__", [])
10161019
if not isinstance(notes, Sequence) or isinstance(notes, (str, bytes)):
10171020
notes = [_safe_string(notes, "__notes__", func=repr)]

0 commit comments

Comments
 (0)
0