forked from exasol/bucketfs-utils-python
-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Here is the offending piece of code
The write method is supposed to take data in one of three forms:
- A byte-stream-like object, e.g. returned by
open() - ByteString
- An Iterable of ByteStrings.
The code is faulty in two ways.
- The test
not isinstance(data, IOBase) and isinstance(data, Iterable)does not rule out a stream-like object. For exampletempfile.NamedTemporaryFilepasses the test. - By iterating over the "chunks" in the test the iterator can be exhausted, so the next line -
b"".join(tmp_file)- will return an empty ByteString.
The bug is first of all in the interface. The Iterable option was unnecessary. Since it is already out there, a reasonable compromise is changing the type from Iterable to Sequence. Then change the test to
if isinstance(tmp_file, Sequence):
# optionally
if not all(isinstance(chunk, ByteString) for chunk in tmp_file):
raise ValueError(...)
...
It should not effect the user code, since an Iterable, if it's actually an Iterable and not a Sequence, wouldn't work anyway.
Metadata
Metadata
Assignees
Labels
No labels