Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

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

未關閉
#160,030 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
python
領域
backend

研究方向

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.

由索引模型根據 Issue 內容生成。

描述

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
主要語言
Python
星號
77.7k
分支
38.3k
平均合併
13 小時 43 分鐘
30 天內合併 PR
704

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

python/cpython 的其他 Issue

查看 python/cpython 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。