Skip to content

winsound.PlaySound should accept pathlib.Path instances #91061

Closed

Description

@Julian-O
mannequin
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']

Activity

  1. Julian-O commented on Mar 3, 2022

    Julian-Omannequin
    MannequinAuthor

    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.

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-featureA feature request or enhancement
    on Mar 3, 2022
  3. eryksun commented on Mar 3, 2022

    @eryksun
    Contributor

    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.

  4. transferred this issue fromon Apr 10, 2022
  5. moribellamy commented on Apr 12, 2022

    @moribellamy
    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)

  6. zware commented on Apr 12, 2022

    @zware
    Member

    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.

  7. added a commit that references this issue on Apr 12, 2022
  8. moribellamy commented on Apr 13, 2022

    @moribellamy
    Contributor

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

  9. added a commit that references this issue on May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixesOS-windowseasystdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions