From 9f6d060ec69ea392a0fbf4d715fd1d10bc6f0bf6 Mon Sep 17 00:00:00 2001 From: Felipe Fumero Date: Sat, 21 Nov 2026 14:28:55 -0600 Subject: [PATCH] fix: allow chained stream reads with no size --- b2sdk/_internal/stream/chained.py | 2 +- changelog.d/+chained-stream-read-none.fixed.md | 1 + test/unit/stream/test_regression_streams.py | 18 +++--------------- 3 files changed, 5 insertions(+), 16 deletions(-) create mode 100644 changelog.d/+chained-stream-read-none.fixed.md diff --git a/b2sdk/_internal/stream/chained.py b/b2sdk/_internal/stream/chained.py index 90fcbb842..5a3962663 100644 --- a/b2sdk/_internal/stream/chained.py +++ b/b2sdk/_internal/stream/chained.py @@ -97,7 +97,7 @@ def read(self, size=None): """ byte_arrays = [] - if size < 0 or size is None: + if size is None or size < 0: while 1: current_stream = self.stream buff = current_stream.read() diff --git a/changelog.d/+chained-stream-read-none.fixed.md b/changelog.d/+chained-stream-read-none.fixed.md new file mode 100644 index 000000000..bdcff774e --- /dev/null +++ b/changelog.d/+chained-stream-read-none.fixed.md @@ -0,0 +1 @@ +Fix reading a chained stream when the size is omitted or None. diff --git a/test/unit/stream/test_regression_streams.py b/test/unit/stream/test_regression_streams.py index b176422eb..bdffe4a01 100644 --- a/test/unit/stream/test_regression_streams.py +++ b/test/unit/stream/test_regression_streams.py @@ -31,7 +31,7 @@ UploadSourceStreamRange, ) from b2sdk._internal.utils import hex_sha1_of_unlimited_stream -from test.known_defect import DefectStillPresent, defect_raises, expect, known_defect +from test.known_defect import DefectStillPresent, expect, known_defect class ShortReadStream(io.RawIOBase): @@ -88,28 +88,16 @@ def test_c46_read_none_stays_within_range(self): class TestChainedStream: - @known_defect( - 'C11', - 'ChainedStream.read() with the default size raises TypeError instead of reading everything', - raises=DefectStillPresent, - ) def test_c11_default_read_returns_everything(self): """C11: read() with default size reads everything (docs), not a TypeError.""" stream = ChainedStream([lambda: io.BytesIO(b'abc'), lambda: io.BytesIO(b'def')]) - with defect_raises(TypeError, match="'<' not supported between instances of 'NoneType'"): - data = stream.read() + data = stream.read() assert data == b'abcdef', 'read() did not return all data' - @known_defect( - 'C11', - 'ChainedStream.read(None) raises TypeError instead of reading everything', - raises=DefectStillPresent, - ) def test_c11_explicit_none_returns_everything(self): """C11: read(None) is documented as 'read everything'.""" stream = ChainedStream([lambda: io.BytesIO(b'abc'), lambda: io.BytesIO(b'def')]) - with defect_raises(TypeError, match="'<' not supported between instances of 'NoneType'"): - data = stream.read(None) + data = stream.read(None) assert data == b'abcdef', 'read(None) did not return all data' def test_c12_guard_sized_reads_cross_stream_boundaries(self):