◐ Shell
clean mode source ↗

Message 263760 - Python tracker

> Hmm, if `sys.__stdout__` was deleted (or set to `None`), this would also raise an `AttributeError` when calling `shutil.get_terminal_size`, so I think that even if `os.get_terminal_size` is guaranteed to be always present (which it's not, IIUC), catching `AttributeError` would prevent that bug, too.

It would be nice to have an unit test too for this case. You can use something like:

with unittest.mock.patch('shutil.sys') as mock_sys:
    del mock_sys.__stdout__
    print(shutil.get_terminal_size((3, 3)))

(and mock also os.envion, as shown in the review.)