Skip to content

compression.zstd.open() names the wrong mode in its invalid mode error #161730

Open

Description

@andresdelfino

Bug report

Bug description:

compression.zstd.open() rejects a mode that contains both 't' and 'b', but the error message names a different mode than the one passed:

>>> import io
>>> from compression import zstd
>>> zstd.open(io.BytesIO(zstd.compress(b'x')), 'rtb')
Traceback (most recent call last):
  ...
ValueError: Invalid mode: 'rb'

'rb' is a valid mode. open() removes 't' from the mode before checking for 'b', and the message is formatted with the modified string:

text_mode = 't' in mode
mode = mode.replace('t', '')

if text_mode:
    if 'b' in mode:
        raise ValueError(f'Invalid mode: {mode!r}')

gzip.open(), bz2.open() and lzma.open() report the mode as passed (Invalid mode: 'rtb').

CPython versions tested on:

3.14, 3.15, CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Nov 10, 2026
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions