[3.13] gh-118893: Evaluate all statements in the new REPL separately (GH-119318) (#119408)

(cherry picked from commit a3e4fec873)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Miss Islington (bot) 2024-05-22 18:22:01 +02:00 committed by GitHub
parent eafd633fac
commit a463cd8e45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 128 additions and 9 deletions

View file

@ -155,7 +155,7 @@ def format_exception(exc, /, value=_sentinel, tb=_sentinel, limit=None, \
return list(te.format(chain=chain, colorize=colorize))
def format_exception_only(exc, /, value=_sentinel, *, show_group=False):
def format_exception_only(exc, /, value=_sentinel, *, show_group=False, **kwargs):
"""Format the exception part of a traceback.
The return value is a list of strings, each ending in a newline.
@ -170,10 +170,11 @@ def format_exception_only(exc, /, value=_sentinel, *, show_group=False):
:exc:`BaseExceptionGroup`, the nested exceptions are included as
well, recursively, with indentation relative to their nesting depth.
"""
colorize = kwargs.get("colorize", False)
if value is _sentinel:
value = exc
te = TracebackException(type(value), value, None, compact=True)
return list(te.format_exception_only(show_group=show_group))
return list(te.format_exception_only(show_group=show_group, colorize=colorize))
# -- not official API but folk probably use these two functions.