Closed jungerm2 closed 2 years ago
Well, the above-suggested code doesn't quite cut it because there are some IOBase
derived classes that don't have a name attribute. Actually, the tests use BytesIO extensively so the above snippet produces a bunch of AttributeError: '_io.BytesIO' object has no attribute 'name'
errors.
Still, the example above with the context manager should work.
Hi @jungerm2. Sorry for the extremely long time it took me to come back to compress_pickle. What was happening was that the code was failing to raise a TypeError
saying that it is not possible to infer the compression protocol from a file-like object. You must always explicitly pass in the compression protocol that should be used with file-like objects and it says so in the docstring already:
If
"infer"
, the compression method is inferred from the pathextension (only possible if
pathis a
PathType``).
I'll fix the control flow to raise an appropriate TypeError
and not run into the NameError
anymore, and I'll also add a section Raises
to the docstring making this explicit.
Currently, the following snippet does not infer the compression scheme properly and errors:
Which results in the following error:
While the docstring says "a file-like object (
io.BaseIO
instances) [...] will be passed to theBaseCompresser
class", this does not happen. I'd suggest grabbing the filename like so:The error would simply ensure that the variable
_path
is defined. Something more descriptive could be added.Any thoughts on this? I don't have time to submit a PR this week, but I'd be happy to at a later time. Thanks for this excellent library!