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

Offen
#161,730 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
1/5
Geschätzter Aufwand
Unter einer Stunde
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
backend

Rechercherichtung

Start in the compression.zstd.open() implementation where it removes 't' from the mode before raising ValueError; inspect the equivalent gzip.open(), bz2.open() and lzma.open() behavior for context. The issue names no test file, so locate the existing zstd open mode tests and add coverage for 'rtb'; done when the error reports the original mode.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

stdlib type-bug
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
  • gh-161731
Vorherrschende Sprache
Python
Sterne
78.2k
Forks
36.6k
Ø Merge
19 Std. 57 Min.
Gemergte PRs (30 T.)
630

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python/cpython

Alle Issues in python/cpython

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.