8000 winsound.PlaySound should accept pathlib.Path instances · Issue #91061 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

winsound.PlaySound should accept pathlib.Path instances #91061

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

Closed
Julian-O mannequin opened this issue Mar 3, 2022 · 5 comments
Closed

winsound.PlaySound should accept pathlib.Path instances #91061

Julian-O mannequin opened this issue Mar 3, 2022 · 5 comments
Labels
3.11 only security fixes easy OS-windows stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@Julian-O
Copy link
Mannequin
Julian-O mannequin commented Mar 3, 2022
BPO 46905
Nosy @pfmoore, @tjguk, @zware, @eryksun, @zooba, @Julian-O

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2022-03-03.00:02:59.656>
labels = ['easy', 'type-feature', 'library', 'OS-windows', '3.11']
title = 'winsound.PlaySound should accept pathlib.Path instances'
updated_at = <Date 2022-03-03.06:53:50.243>
user = 'https://github.com/Julian-O'

bugs.python.org fields:

activity = <Date 2022-03-03.06:53:50.243>
actor = 'eryksun'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)', 'Windows']
creation = <Date 2022-03-03.00:02:59.656>
creator = 'Julian-O'
dependencies = []
files = []
hgrepos = []
issue_num = 46905
keywords = ['easy (C)']
message_count = 2.0
messages = ['414393', '414408']
nosy_count = 6.0
nosy_names = ['paul.moore', 'tim.golden', 'zach.ware', 'eryksun', 'steve.dower', 'Julian-O']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue46905'
versions = ['Python 3.11']

@Julian-O
Copy link
Mannequin Author
Julian-O mannequin commented Mar 3, 2022

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.

@Julian-O Julian-O mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Mar 3, 2022
@eryksun
Copy link
Contributor
eryksun commented Mar 3, 2022

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.

@eryksun eryksun added 3.11 only security fixes easy OS-windows labels Mar 3, 2022
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@moribellamy
Copy link
Contributor

I'm interested in trying this issue. What's an appropriate way to test the fix in CI? I'm assuming manual testing will be straightforward (just build the binary and have a simple script that tries to use a PathLib.Path instead of a string)

@zware
Copy link
Member
zware commented Apr 12, 2022

About the best you can do is replicate this test:

def test_snd_filename(self):
fn = support.findfile('pluck-pcm8.wav', subdir='audiodata')
safe_PlaySound(fn, winsound.SND_FILENAME | winsound.SND_NODEFAULT)
and pass in pathlib.Path(fn) instead of just fn.

moribellamy added a commit to moribellamy/cpython that referenced this issue Apr 12, 2022
@moribellamy
Copy link
Contributor

Thanks all. My first ever python PR is out. Looking forward to learning how to do things properly :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes easy OS-windows stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants
0