Author: marky1991
Branch: py3.3
Changeset: r81715:03591a1499c8
Date: 2016-01-10 15:07 -0500
http://bitbucket.org/pypy/pypy/changeset/03591a1499c8/
Log: Match commenting style to PEP-8 as requested. Also, went ahead and
fixed the code module to mostly match py3k.
diff --git a/lib-python/3/code.py b/lib-python/3/code.py
--- a/lib-python/3/code.py
+++ b/lib-python/3/code.py
@@ -105,10 +105,9 @@
The output is written by self.write(), below.
"""
- type, value, tb = sys.exc_info()
+ type, value, sys.last_traceback = sys.exc_info()
sys.last_type = type
sys.last_value = value
- sys.last_traceback = tb
if filename and type is SyntaxError:
# Work hard to stuff the correct filename in the exception
try:
@@ -126,7 +125,7 @@
else:
# If someone has set sys.excepthook, we let that take precedence
# over self.write
- sys.excepthook(type, value, tb)
+ sys.excepthook(type, value, self.last_traceback)
def showtraceback(self):
"""Display the exception that just occurred.
@@ -136,25 +135,35 @@
The output is written by self.write(), below.
"""
+ sys.last_type, sys.last_value, last_tb = ei = sys.exc_info()
+ sys.last_traceback = last_tb
try:
- type, value, tb = sys.exc_info()
- sys.last_type = type
- sys.last_value = value
- sys.last_traceback = tb
- tblist = traceback.extract_tb(tb)
- del tblist[:1]
- lines = traceback.format_list(tblist)
- if lines:
- lines.insert(0, "Traceback (most recent call last):\n")
- lines.extend(traceback.format_exception_only(type, value))
+ lines = []
+ for value, tb in traceback._iter_chain(*ei[1:]):
+ if isinstance(value, str):
+ lines.append(value)
+ lines.append('\n')
+ continue
+ if tb:
+ tblist = traceback.extract_tb(tb)
+ if tb is last_tb:
+ # The last traceback includes the frame we
+ # exec'd in
+ del tblist[:1]
+ tblines = traceback.format_list(tblist)
+ if tblines:
+ lines.append("Traceback (most recent call last):\n")
+ lines.extend(tblines)
+ lines.extend(traceback.format_exception_only(type(value),
+ value))
finally:
- tblist = tb = None
+ tblist = last_tb = ei = None
if sys.excepthook is sys.__excepthook__:
self.write(''.join(lines))
else:
# If someone has set sys.excepthook, we let that take precedence
# over self.write
- sys.excepthook(type, value, tb)
+ sys.excepthook(sys.last_type, sys.last_value, last_tb)
def write(self, data):
"""Write a string.
diff --git a/pypy/module/__pypy__/test/test_stderrprinter.py
b/pypy/module/__pypy__/test/test_stderrprinter.py
--- a/pypy/module/__pypy__/test/test_stderrprinter.py
+++ b/pypy/module/__pypy__/test/test_stderrprinter.py
@@ -7,9 +7,9 @@
p.close() # this should be a no-op
p.flush() # this should be a no-op
assert p.fileno() == 2
- #It doesn't make sense to assert this. Stderror could be a tty (the
terminal)
- #or not, depending on how we are running the tests.
- #assert p.isatty()
+ # It doesn't make sense to assert this. Stderror could be a tty
+ # (the terminal) or not, depending on how we are running the tests.
+ # assert p.isatty()
assert p.write('foo') == 3
raises(TypeError, p.write, b'foo')
diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py
--- a/pypy/module/imp/interp_imp.py
+++ b/pypy/module/imp/interp_imp.py
@@ -84,8 +84,8 @@
name = space.str0_w(w_name)
if name not in space.builtin_modules:
return
- #This is needed to make reload actually reload instead of just using the
- #already-present module in sys.modules.
+ # force_init is needed to make reload actually reload instead of just
+ # using the already-present module in sys.modules.
return space.getbuiltinmodule(name, force_init=True)
def init_frozen(space, w_name):
diff --git a/pypy/module/sys/test/test_sysmodule.py
b/pypy/module/sys/test/test_sysmodule.py
--- a/pypy/module/sys/test/test_sysmodule.py
+++ b/pypy/module/sys/test/test_sysmodule.py
@@ -32,7 +32,7 @@
w_sys.flush_std_files(space)
msg = space.bytes_w(space.call_function(w_read))
- #IOError has become an alias for OSError
+ # IOError has become an alias for OSError
assert 'Exception OSError' in msg
finally:
space.setattr(w_sys, space.wrap('stdout'), w_sys.get('__stdout__'))
diff --git a/pypy/module/test_lib_pypy/test_code_module.py
b/pypy/module/test_lib_pypy/test_code_module.py
--- a/pypy/module/test_lib_pypy/test_code_module.py
+++ b/pypy/module/test_lib_pypy/test_code_module.py
@@ -21,21 +21,17 @@
def test_cause_tb(self):
interp = self.get_interp()
- #(Arbitrarily) Changing to TypeError as IOError is now an alias of
OSError, making
- #testing confusing
+ # (Arbitrarily) Changing to TypeError as IOError is now an alias of
+ # OSError, making testing confusing
interp.runsource('raise TypeError from OSError')
result = interp.out.getvalue()
- #For reasons to me unknown, the code module does not show chained
exceptions
- #It only shows the last exception. Keeping this for now.
- #The test needs to me moved elsewhere if chained exceptions aren't
- #already tested elsewhere
expected_header = """OSError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
"""
- #assert expected_header in result
+ assert expected_header in result
assert result.endswith("TypeError\n")
def test_context_tb(self):
@@ -51,5 +47,5 @@
Traceback (most recent call last):
"""
- #assert expected_header in result
+ assert expected_header in result
assert result.endswith("NameError: name '_diana_' is not defined\n")
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit