mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-33809: add the TracebackException.print() method (GH-24231)
This commit is contained in:
parent
9e746e3298
commit
220dd80a26
4 changed files with 34 additions and 4 deletions
|
@ -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="")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue