ZipFile.writestr doesn't behave like Path.write_*
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Feature or enhancement
Proposal:
Given that ZipPath doesn't provide a write_text or write_bytes, I'm trying to use ZipFile.writestr and noticed that when the data you're trying to write isn't the right type it still stores an empty entry. I didn't expect side effects when it failed this fundamentally to get the data.
import zipfile
with zipfile.ZipFile("foo.zip", "w") as z:
z.writestr("x", ())
print(z.namelist()) # -> "x"
Notably, Path.write_text behaves the way I'd expect -- it has to construct a memoryview successfully first before opening the file.
from pathlib import Path
Path("x").write_bytes(()) # -> neither creates nor truncates
@jaraco I assume ZipPath not supporting writes is intentional?
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
La issue non indica alcun file di implementazione né alcun test. Inizia riproducendo l’esempio di zipfile.ZipFile.writestr e confrontandolo con pathlib.Path.write_bytes per dati non validi; esamina l’implementazione e i test pertinenti della libreria standard. Il lavoro è completo quando un input non valido genera un errore senza creare né troncare la voce dell’archivio.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100