Skip to content

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

Open

Description

@n1snt

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Oct 21, 2026
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Oct 21, 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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions