Skip to content

Commit 9ff569c

Browse files
authored
Fix initialize_unix_colors when sys.stdout is overridden with a TextIO (#8388)
1 parent 1104a9f commit 9ff569c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

mypy/util.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,14 @@ def initialize_unix_colors(self) -> bool:
542542
if not CURSES_ENABLED:
543543
return False
544544
try:
545-
curses.setupterm()
545+
# setupterm wants a fd to potentially write an "initialization sequence".
546+
# We override sys.stdout for the daemon API so if stdout doesn't have an fd,
547+
# just give it /dev/null.
548+
if hasattr(sys.stdout, 'fileno'):
549+
curses.setupterm()
550+
else:
551+
with open("/dev/null", "rb") as f:
552+
curses.setupterm(fd=f.fileno())
546553
except curses.error:
547554
# Most likely terminfo not found.
548555
return False

0 commit comments

Comments
 (0)