diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst index 11c67074921..22d6dba9e1a 100644 --- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -804,6 +804,10 @@ Querying the size of the output terminal .. versionadded:: 3.3 + .. versionchanged:: 3.11 + The ``fallback`` values are also used if :func:`os.get_terminal_size` + returns zeroes. + .. _`fcopyfile`: http://www.manpagez.com/man/3/copyfile/ diff --git a/Lib/shutil.py b/Lib/shutil.py index e544498fca7..949e024853c 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -1372,9 +1372,9 @@ def get_terminal_size(fallback=(80, 24)): # os.get_terminal_size() is unsupported size = os.terminal_size(fallback) if columns <= 0: - columns = size.columns + columns = size.columns or fallback[0] if lines <= 0: - lines = size.lines + lines = size.lines or fallback[1] return os.terminal_size((columns, lines)) diff --git a/Misc/NEWS.d/next/Library/2021-10-19-01-30-57.bpo-42174.O2w9bi.rst b/Misc/NEWS.d/next/Library/2021-10-19-01-30-57.bpo-42174.O2w9bi.rst new file mode 100644 index 00000000000..412582ded3e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-10-19-01-30-57.bpo-42174.O2w9bi.rst @@ -0,0 +1,2 @@ +:meth:`shutil.get_terminal_size` now falls back to sane values if the column +or line count are 0.