Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up terminal width handling (#9143)
* Remove fixed_terminal_width from utils.colorize docstring This was added by 91adf61, yet colorize() doesn't actually have a fixed_terminal_width argument. * Move MYPY_FORCE_TERMINAL_WIDTH handling into get_terminal_width() Those two callers are the only two, and both check MYPY_FORCE_TERMINAL_WIDTH before calling get_terminal_width(). * Use shutil.get_terminal_size() The documentation for Python's os.get_terminal_size() says: shutil.get_terminal_size() is the high-level function which should normally be used, os.get_terminal_size is the low-level implementation. https://docs.python.org/3/library/os.html#os.get_terminal_size shutil.get_terminal_size() already takes care of various corner cases such as: - Providing a fallback (to 80 columns, like the current DEFAULT_COLUMNS) - Returning that fallback if os.get_terminal_size() raises OSError - Doing the same if it returns a size of 0 In addition to that: - It takes care of some more corner cases ("stdout is None, closed, detached, or not a terminal, or os.get_terminal_size() is unsupported") - It adds support for the COLUMNS environment variable (rather than the non-standard MYPY_FORCE_TERMINAL_WIDTH) https://github.com/python/cpython/blob/v3.8.3/Lib/shutil.py#L1298-L1341
- Loading branch information