Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

wave.Wave_write.setparams() rejects valid PCM-to-IEEE-float parameter changes

Aberta
#160,030 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
35/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
python
Domínio
backend

Direção de pesquisa

The issue identifies Lib/wave.py, specifically Wave_write.setparams(), setformat(), and setsampwidth(). Read those methods and the tests for IEEE float support, then reproduce the PCM-to-float reconfiguration case from the report. Done means valid 4-byte and 8-byte float parameters can be set before any frames are written, including after PCM widths of 1, 2, or 3 bytes.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

stdlib type-bug
Bug report
Bug description

wave.Wave_write.setparams() rejects valid IEEE-float parameters when the writer was previously configured with a PCM sample width of 1, 2, or 3 bytes, even though no audio frames have been written.

The same parameters succeed on a fresh writer.

Reproducer
import io
import wave

float_params = (
    1, 4, 8000, 0, "NONE", "not compressed",
    wave.WAVE_FORMAT_IEEE_FLOAT,
)

with wave.open(io.BytesIO(), "wb") as writer:
    writer.setparams(float_params)
    print("Fresh writer: OK")

with wave.open(io.BytesIO(), "wb") as writer:
    writer.setparams((1, 2, 8000, 0, "NONE", "not compressed"))
    writer.setparams(float_params)
    print("Reconfigured writer: OK")
Actual behavior

The fresh-writer configuration succeeds. Reconfiguring the PCM writer raises:

wave.Error: unsupported sample width for IEEE float format
Expected behavior

Both configurations should succeed. The new sample width is 4 bytes, which is supported for IEEE float, and no frames have been written.

Implementation details

Wave_write.setparams() calls setformat(format) before
setsampwidth(sampwidth).

However, setformat() validates the existing self._sampwidth against the
new format. This rejects the previous 2-byte PCM width before the valid
new 4-byte width can be installed.

The same failure occurs when switching from PCM widths of 1, 2, or 3 bytes
to either 4-byte or 8-byte IEEE float. Switching from 4-byte PCM succeeds.

Related: #60729 added IEEE-float support.

CPython versions tested on

Python 3.16.0a1+dev, debug build based on commit 8b7d6c53eee.

Also reproduced using Lib/wave.py from upstream commit
f5bd07700ecd0f02cc424666b871f51de03b9232, executed under Python 3.14.8.
This additional check was not a full build of that upstream commit.

Operating systems tested on

macOS

Output from running python -VV
Python 3.16.0a1+dev (heads/gh-159868-userstring-affixes-dirty:8b7d6c53eee, Oct 20 2026, 15:46:41) [Clang 21.0.0 (clang-2100.3.34.2)]
CPython versions tested on:

3.16

Operating systems tested on:

macOS

Linked PRs
  • gh-160031
Linguagem predominante
Python
Estrelas
77.7k
Forks
38.3k
Merge médio
13h 43min
PRs com merge (30d)
704

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de python/cpython

Todas as issues de python/cpython

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.