From 35ed96f9dd859f4ebc8b0a3b14398a280809dfc6 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Wed, 12 Feb 2020 12:11:08 -0800 Subject: [PATCH] Actually fix the api curses crash. I refactored after I tested, which was a mistake. --- mypy/util.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mypy/util.py b/mypy/util.py index c75aec7a89d4..fe36297d297a 100644 --- a/mypy/util.py +++ b/mypy/util.py @@ -5,6 +5,7 @@ import subprocess import sys import hashlib +import io from typing import ( TypeVar, List, Tuple, Optional, Dict, Sequence, Iterable, Container, IO, Callable @@ -545,11 +546,13 @@ def initialize_unix_colors(self) -> bool: # setupterm wants a fd to potentially write an "initialization sequence". # We override sys.stdout for the daemon API so if stdout doesn't have an fd, # just give it /dev/null. - if hasattr(sys.stdout, 'fileno'): - curses.setupterm() - else: + try: + fd = sys.stdout.fileno() + except io.UnsupportedOperation: with open("/dev/null", "rb") as f: curses.setupterm(fd=f.fileno()) + else: + curses.setupterm(fd=fd) except curses.error: # Most likely terminfo not found. return False