classification
Title: shutil.get_terminal_size() returns 0 when run in a pty
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.9
process
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 https://github.com/python/mypy/issues/8144#issue-537760245:

$ python3 t.py 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:
https://github.com/pre-commit/mirrors-mypy/issues/29
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:

https://github.com/willmcgugan/rich/blob/v9.1.0/rich/console.py#L669-L672
History
Date User Action Args
2020-11-02 14:23:22The Compilersetmessages: + msg380224
2020-10-27 16:32:31The Compilercreate