Now, traceback.format_exception_only doesn’t support traceback object. However, for AttributeError and NameError, whether containing traceback will influence the final message. The suggestion is change it to:
def format_exception_only(exc, /, value=_sentinel, tb=_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.
The list contains the exception's message, which is
normally a single string; however, for :exc:`SyntaxError` exceptions, it
contains several lines that (when printed) display detailed information
about where the syntax error occurred. Following the message, the list
contains the exception's ``__notes__``.
When *show_group* is ``True``, and the exception is an instance of
: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
if tb is _sentinel:
tb = None
te = TracebackException(type(value), value, tb, compact=True)
return list(te.format_exception_only(show_group=show_group, colorize=colorize))