diff --git a/Lib/compression/zstd/_zstdfile.py b/Lib/compression/zstd/_zstdfile.py index 26d7c9006375fb..f504c92d1fa143 100644 --- a/Lib/compression/zstd/_zstdfile.py +++ b/Lib/compression/zstd/_zstdfile.py @@ -325,11 +325,11 @@ def open(file, /, mode='rb', *, level=None, options=None, zstd_dict=None, """ text_mode = 't' in mode - mode = mode.replace('t', '') if text_mode: if 'b' in mode: raise ValueError(f'Invalid mode: {mode!r}') + mode = mode.replace('t', '') else: if encoding is not None: raise ValueError('Argument "encoding" not supported in binary mode') diff --git a/Misc/NEWS.d/next/Library/2026-11-09-23-37-08.gh-issue-161730.hh7MVs.rst b/Misc/NEWS.d/next/Library/2026-11-09-23-37-08.gh-issue-161730.hh7MVs.rst new file mode 100644 index 00000000000000..db673f4e95ea14 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-11-09-23-37-08.gh-issue-161730.hh7MVs.rst @@ -0,0 +1,2 @@ +Fix :func:`compression.zstd.open` naming the wrong mode in the error message +for an invalid mode that contains both ``'t'`` and ``'b'``.