Skip to content

Commit

Permalink
bugfix: ValueError: underlying buffer has been detached (erikrose#129)
Browse files Browse the repository at this point in the history
Prevent error condition, ValueError: underlying buffer has been detached from raising, Closes erikrose#126
  • Loading branch information
jquast authored Jan 17, 2020
1 parent 56e1ede commit 8e07054
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion blessed/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ def __init__(self, kind=None, stream=None, force_styling=False):
try:
stream_fd = (stream.fileno() if hasattr(stream, 'fileno') and
callable(stream.fileno) else None)
except io.UnsupportedOperation:
except (io.UnsupportedOperation, ValueError):
# The stream is not a file, such as the case of StringIO, or, when it has been
# "detached", such as might be the case of stdout in some test scenarios.
stream_fd = None

self._stream = stream
Expand Down
2 changes: 2 additions & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Version History
* introduced: 24-bit color support, detected by ``term.number_of_colors == 1 << 24``,
and 24-bit color foreground method :meth:`~Terminal.color_rgb` and background method
:meth:`~Terminal.on_color_rgb`.
* bugfix: prevent error condition, ``ValueError: underlying buffer has been detached`` in rare
conditions where sys.__stdout__ has been detached in test frameworks. :ghissue:`126`.
* bugfix: off-by-one error in :meth:`~.Terminal.get_location`, now accounts for
``%i`` in cursor_report, :ghissue:`94`.
* bugfix :meth:`~Terminal.split_seqs` and related functions failed to match when the
Expand Down

0 comments on commit 8e07054

Please sign in to comment.