aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/traceback.py
diff options
context:
space:
mode:
authorIrit Katriel <iritkatriel@yahoo.com>2021-05-22 17:39:33 +0100
committerGitHub <noreply@github.com>2021-05-22 17:39:33 +0100
commit220dd80a2671f57486055955d5422163cf73ed33 (patch)
tree04cc9fcda487050f9978e42f6682d6a51a92f8ec /Lib/traceback.py
parent9e746e3298da36f4e8df0495f91a720f3e54ea33 (diff)
downloadcpython-220dd80a2671f57486055955d5422163cf73ed33.tar.gz
cpython-220dd80a2671f57486055955d5422163cf73ed33.zip
bpo-33809: add the TracebackException.print() method (GH-24231)
Diffstat (limited to 'Lib/traceback.py')
-rw-r--r--Lib/traceback.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/traceback.py b/Lib/traceback.py
index 8f908dd2e09..e19745df6de 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -111,11 +111,8 @@ def print_exception(exc, /, value=_sentinel, tb=_sentinel, limit=None, \
position of the error.
"""
value, tb = _parse_value_tb(exc, value, tb)
- if file is None:
- file = sys.stderr
te = TracebackException(type(value), value, tb, limit=limit, compact=True)
- for line in te.format(chain=chain):
- print(line, file=file, end="")
+ te.print(file=file, chain=chain)
def format_exception(exc, /, value=_sentinel, tb=_sentinel, limit=None, \
@@ -669,3 +666,10 @@ class TracebackException:
yield 'Traceback (most recent call last):\n'
yield from exc.stack.format()
yield from exc.format_exception_only()
+
+ def print(self, *, file=None, chain=True):
+ """Print the result of self.format(chain=chain) to 'file'."""
+ if file is None:
+ file = sys.stderr
+ for line in self.format(chain=chain):
+ print(line, file=file, end="")