gh-75593: Add support of bytes and path-like paths in wave.open() (GH-140951)

This commit is contained in:
Mark Byrne 2025-11-12 09:20:55 +01:00 committed by GitHub
parent f1b7961ccf
commit 35908265b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 4 deletions

View file

@ -69,6 +69,7 @@
from collections import namedtuple
import builtins
import os
import struct
import sys
@ -274,7 +275,7 @@ def initfp(self, file):
def __init__(self, f):
self._i_opened_the_file = None
if isinstance(f, str):
if isinstance(f, (bytes, str, os.PathLike)):
f = builtins.open(f, 'rb')
self._i_opened_the_file = f
# else, assume it is an open file object already
@ -431,7 +432,7 @@ class Wave_write:
def __init__(self, f):
self._i_opened_the_file = None
if isinstance(f, str):
if isinstance(f, (bytes, str, os.PathLike)):
f = builtins.open(f, 'wb')
self._i_opened_the_file = f
try: