[PATCH 1/1] _tty_width: return 70 if get_terminal_size returns zero

1 view
Skip to first unread message

Rob Browning

unread,
Aug 31, 2025, 4:16:36 PMAug 31
to bup-...@googlegroups.com
Apparently some versions of python can return zero and some
can't. Just return the same default (70) for that case that we do for
OSError (not a terminal). The zero crashed the textwrap call.

cf. https://github.com/python/cpython/issues/86340

Signed-off-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
---

Proposed for main.

lib/bup/options.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/bup/options.py b/lib/bup/options.py
index 890c3b8b..1e357513 100644
--- a/lib/bup/options.py
+++ b/lib/bup/options.py
@@ -128,9 +128,11 @@ def _intify(v):
def _tty_width():
try:
size = os.get_terminal_size(sys.stderr.fileno())
+ # May return 0 for some python versions:
+ # https://github.com/python/cpython/issues/86340
+ return size.columns or 70
except OSError:
return 70
- return size.columns


class Options:
--
2.47.2

Reply all
Reply to author
Forward
0 new messages