indygreg / indygreg/python-zstandard
`fileno` not available on `ZstdDecompressionReader`
- Dominant language
- C
- Stars
- 642
- Forks
- 116
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 5
Description
According to the shipped typing stubs, `ZstdDecompressionReader` implements the `typing.BinaryIO` interface.
Unfortunately, it lacks the `fileno()` method that is promised by `BinaryIO` so this is a bit of a lie.
This breaks when trying to do something like:
```
>>> f = open('foo.zstd', 'rb')
>>> d = zstandard.ZstdDecompressor()
>>> g = d.stream_reader(f)
>>> subprocess.run(['cat'], stdin = g)
Traceback (most recent call last):
File "", line 1, in
File "/Users/spaans/.pyenv/versions/3.12.1/lib/python3.12/subprocess.py", line 548, in run
with Popen(*popenargs, **kwargs) as process:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/spaans/.pyenv/versions/3.12.1/lib/python3.12/subprocess.py", line 992, in __init__
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/spaans/.pyenv/versions/3.12.1/lib/python3.12/subprocess.py", line 1708, in _get_handles
p2cread = stdin.fileno()
^^^^^^^^^^^^
AttributeError: 'zstd.ZstdDecompressionReader' object has no attribute 'fileno'
```
Note that `StringIO` in the standard library also doesn't support `fileno`, but has instead chosen to raise an Exception when it is used like this, so a possible solution could be to just mimic that behaviour.
Contributor guide
Research direction
Start with the shipped typing stubs and the ZstdDecompressionReader entry point, then reproduce the subprocess.run example from the issue. Define and test the intended fileno() behavior, including the StringIO-style exception possibility, so the reader no longer contradicts its BinaryIO interface.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100