Title: shutil.get_terminal_size() returns 0 when run in a pty
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: The Compiler, giampaolo.rodola, tarek
Priority: normal Keywords:

Created on 2020-10-27 16:32 by The Compiler, last changed 2020-11-02 14:23 by The Compiler.

Messages (2)
msg379773 - (view) Author: Florian Bruhin (The Compiler) * Date: 2020-10-27 16:32
When shutil.get_terminal_size() is used in a PTY, the os.get_terminal_size() call can return (0, 0).

With the pty script from

$ python3 python3 -c 'import shutil; print(shutil.get_terminal_size())'        
os.terminal_size(columns=0, lines=0)

While the following cases *are* handled by returning the fallback:

- COLUMNS or lines being non-existent or 0
- os.get_terminal_size raising

The case of os.get_terminal_size() succeeding but returning (0, 0) should probably be handled the same way as well.

This e.g. affects mypy when run with pre-commit:
msg380224 - (view) Author: Florian Bruhin (The Compiler) * Date: 2020-11-02 14:23
Just found another workaround for this in the wild, as part of the "rich" library:
Date User Action Args
2020-11-02 14:23:22The Compilersetmessages: + msg380224
2020-10-27 16:32:31The Compilercreate