Content-Length: 305127 | pFad | https://github.com/python/cpython/issues/153037

ad `ZstdFile` raises `AttributeError` instead of `io.UnsupportedOperation` when iterating over a non-readable file · Issue #153037 · python/cpython · GitHub
Skip to content

ZstdFile raises AttributeError instead of io.UnsupportedOperation when iterating over a non-readable file #153037

Description

@lkk7

Bug report

Bug description:

All other compression modules raise io.UnsupportedOperation when iterating over a non-readable file:

next(iter(lzma.LZMAFile(io.BytesIO(), "w")))   # io.UnsupportedOperation: File not open for reading
next(iter(bz2.BZ2File(io.BytesIO(), "w")))     # io.UnsupportedOperation: ...
next(iter(gzip.GzipFile(fileobj=io.BytesIO(), mode="w")))  # ...

But ZstdFile.__next__ doesn't call _check_can_read(), so it dereferences self._buffer, which is None in write mode:

import io
from compression.zstd import ZstdFile

next(iter(ZstdFile(io.BytesIO(), "w")))

This results in:

AttributeError: 'NoneType' object has no attribute 'readline'

CPython versions tested on:

3.14, 3.15, CPython main branch

Operating systems tested on:

macOS, but it does not depend on OS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/153037

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy