Skip to content
Prev Previous commit
Next Next commit
Implement extra checks in can_colorize
  • Loading branch information
pablogsal committed Apr 10, 2024
commit 73a4fb1de588c4ef824f385c441c2b67674260e1
5 changes: 5 additions & 0 deletions Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,16 @@ def _can_colorize():
return True
if os.environ.get("TERM") == "dumb":
return False

if not hasattr(sys.stderr, "fileno"):
return False

try:
return os.isatty(sys.stderr.fileno())
except io.UnsupportedOperation:
return sys.stderr.isatty()


def _print_exception_bltin(exc, /):
file = sys.stderr if sys.stderr is not None else sys.__stderr__
colorize = _can_colorize()
Expand Down