-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
gh-75593: Allow opening of path-like files with wave.open
#140951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
serhiy-storchaka
merged 10 commits into
python:main
from
mbyrnepr2:wave_open_a_pathlib_file
Nov 12, 2025
+33
−4
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
99e7d5a
wave.py - Allow opening of path-like files.
mbyrnepr2 6475b2c
📜🤖 Added by blurb_it.
blurb-it[bot] a36d5fc
📜🤖 Added by blurb_it.
blurb-it[bot] a09e5c3
Delete Misc/NEWS.d/next/Library/2025-11-03-15-51-42.gh-issue-140952.E…
mbyrnepr2 95b2fce
Update the `wave.py` documentation.
mbyrnepr2 9b96c88
Update Misc/NEWS.d/next/Library/2025-11-04-12-16-13.gh-issue-75593.EF…
mbyrnepr2 ec5b3df
Code review improvements:
mbyrnepr2 ba5ed6f
Remove unused import.
mbyrnepr2 31cc9c5
Use code review improvements:
mbyrnepr2 6c2b7de
Update the news with the full information.
mbyrnepr2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| import unittest | ||
| from test import audiotests | ||
| from test import support | ||
| from test.support.os_helper import FakePath | ||
| import io | ||
| import os | ||
| import struct | ||
| import tempfile | ||
| import sys | ||
| import wave | ||
|
|
||
|
|
@@ -206,5 +208,25 @@ def test_open_in_write_raises(self): | |
| self.assertIsNone(cm.unraisable) | ||
|
|
||
|
|
||
| class WaveOpen(unittest.TestCase): | ||
| def test_open_pathlike(self): | ||
| """It is possible to use `wave.read` and `wave.write` with a path-like object""" | ||
| with tempfile.NamedTemporaryFile(delete_on_close=False) as fp: | ||
| cases = ( | ||
| FakePath(fp.name), | ||
| FakePath(os.fsencode(fp.name)), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test also for |
||
| os.fsencode(fp.name), | ||
| ) | ||
| for fake_path in cases: | ||
| with self.subTest(fake_path): | ||
| with wave.open(fake_path, 'wb') as f: | ||
| f.setnchannels(1) | ||
| f.setsampwidth(2) | ||
| f.setframerate(44100) | ||
|
|
||
| with wave.open(fake_path, 'rb') as f: | ||
| pass | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2025-11-04-12-16-13.gh-issue-75593.EFVhKR.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add support of :term:`path-like objects <path-like object>` and :term:`bytes-like objects <bytes-like object>` in :func:`wave.open`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there a place for this test in an existing class? You can also look in audiotests -- if this was added before removing aifc, the test should be added there.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had also considered adding the new tests to MiscTestCase or WaveLowLevelTest - I don't have a good reason to create a new class now that I think of it, except that perhaps they don't strictly belong in either of those places.
Just to clarify your point about adding the tests to audiotests.py - are you saying that the new tests should simply be moved there instead? Or do you mean that the existing tests in test_wave.py should inherit the new tests similar to the existing design?
My rationale for adding the tests to test_wave.py is I did feel like they belonged in test_wave.py and not audiotests.py since the classes in audiotests.py are inherited by the classes in test_wave.py to assert a range of things which felt redundant for the new tests to also perform.