This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: winsound.PlaySound should accept pathlib.Path instances
Type: enhancement Stage: needs patch
Components: Library (Lib), Windows Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Julian-O, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords: easy (C)

Created on 2022-03-03 00:02 by Julian-O, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg414393 - (view) Author: Julian (Julian-O) Date: 2022-03-03 00:02
The library function winsound.PlaySound takes a sound parameter. One of the valid arguments is a path to a WAV filename.

Since Python 3.4, paths can be cleanly represented with PathLib.Path instances.

However, if you pass a Path instance to PlaySound, it responds with:

   TypeError: 'sound' must be str or None, not 'WindowsPath'

This can be quickly fixed in the caller by passing str(the_path_instance) instead, but it would be cleaner if PlaySound accepted Python's preferred method of representing paths.
msg414408 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2022-03-03 06:52
PlaySound() is implemented by the C function winsound_PlaySound_impl() in "PC/winsound.c". To support pathlike objects, it could use `soundname = PyOS_FSPath(sound)`, and require soundname to be a Unicode string via PyUnicode_Check(soundname). Or it could more generically support any buffer or pathlike object via PyUnicode_FSDecoder(sound, &soundname). This call decodes byte strings using the filesystem encoding, which is UTF-8 unless legacy ANSI mode is enabled.
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 91061
2022-03-03 06:53:50eryksunsetkeywords: + easy (C)
nosy: + paul.moore, tim.golden, steve.dower, zach.ware
components: + Windows
2022-03-03 06:52:43eryksunsetversions: + Python 3.11
nosy: + eryksun

messages: + msg414408

stage: needs patch
2022-03-03 00:02:59Julian-Ocreate