Title: wave: setframerate() accepts invalid frame rate values that round to zero · Issue #144975 · python/cpython · GitHub
Open Graph Title: wave: setframerate() accepts invalid frame rate values that round to zero · Issue #144975 · python/cpython
X Title: wave: setframerate() accepts invalid frame rate values that round to zero · Issue #144975 · python/cpython
Description: Bug report Bug description: The wave.Wave_write.setframerate() method currently validates the frame rate before rounding it to an integer. This allows invalid values like 0.5 to pass validation (since 0.5 > 0), but then get rounded to 0,...
Open Graph Description: Bug report Bug description: The wave.Wave_write.setframerate() method currently validates the frame rate before rounding it to an integer. This allows invalid values like 0.5 to pass validation (si...
X Description: Bug report Bug description: The wave.Wave_write.setframerate() method currently validates the frame rate before rounding it to an integer. This allows invalid values like 0.5 to pass validation (si...
Opengraph URL: https://github.com/python/cpython/issues/144975
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"wave: setframerate() accepts invalid frame rate values that round to zero","articleBody":"# Bug report\n\n### Bug description:\n\nThe `wave.Wave_write.setframerate()` method currently validates the frame rate before rounding it to an integer. This allows invalid values like `0.5` to pass validation (since `0.5 > 0`), but then get rounded to `0`, resulting in an invalid frame rate being stored internally.\n\nThis causes a confusing user experience: `setframerate(0.5)` succeeds silently, but later operations fail with the misleading error message `\"sampling rate not specified\"` instead of raising a clear error at the point where the bad value was provided.\n\nIt was found in the PR review for #132448 by @picnixz but as that PR is not merged and might not get merged, I think it makes sense to raise this separately.\n\n## current behavior\n\n```python\nimport wave\nimport io\n\nf = wave.open(io.BytesIO(), 'wb')\nf.setnchannels(1)\nf.setsampwidth(2)\nf.setframerate(0.5) # No error raised!\nprint(f.getframerate()) # Outputs: 0\n\n# Later, when trying to write:\nf.writeframes(b'\\x00\\x00\\x00\\x00')\n# wave.Error: sampling rate not specified \u003c-- Confusing delayed error!\n```\n\nThe value `0.5` passes the `framerate \u003c= 0` check because `0.5 > 0`, but `int(round(0.5))` evaluates to `0`. This creates a confusing user experience where:\n1. `setframerate(0.5)` succeeds with no error\n2. The error only appears later during `writeframes()` \n3. The error message is misleading: \"not specified\" when a value **was** specified\n\n## expected behavior\n\n`setframerate(0.5)` should immediately raise `wave.Error('bad frame rate')` because the rounded value is `0`, which is invalid. This provides clear, immediate feedback at the point where the error occurs, rather than a confusing delayed error.\n\nI understand that wave files with such low framerates are not usable, but the bug fix is trivial so we should just as well fix this.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-144976\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/mbeijen","@type":"Person","name":"mbeijen"},"datePublished":"2026-02-18T20:27:49Z","url":"https://github.com/python/cpython/issues/144975"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:471bb61f-3891-aa13-4b04-4fd7345e682d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 974C:2B6F5F:138E0EB:1B91EB6:6AECCA17 |
| html-safe-nonce | dbafef6949756eb86685022dffb67d83150f2d119aa30609e56195474d5e802b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzRDOjJCNkY1RjoxMzhFMEVCOjFCOTFFQjY6NkFFQ0NBMTciLCJ2aXNpdG9yX2lkIjoiNTI0MTk1MzA2NjI0NzA0NzcwMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8779c1c8dc7967b9486d8013602c1bded2ff1c3cf7b42c0a8a885c39b43cc572 |
| hovercard-subject-tag | issue:3959647412 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/144975/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1f1edb58d5282f5dd37b9867eed7a03c4334fe93202e604fb1a1cfda94556c16/python/cpython/issues/144975 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1f1edb58d5282f5dd37b9867eed7a03c4334fe93202e604fb1a1cfda94556c16/python/cpython/issues/144975 |
| og:image:alt | Bug report Bug description: The wave.Wave_write.setframerate() method currently validates the frame rate before rounding it to an integer. This allows invalid values like 0.5 to pass validation (si... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mbeijen |
| hostname | github.com |
| expected-hostname | github.com |
| None | dc0b519c5798dc1150b88dc4c06a8b9634d0069218dc04e469970e76aad74016 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | db139f0bf57b59bf9a8c4abb0849924d6c6ca559 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width