diff options
author | Mori Bellamy <mori@invoked.net> | 2022-05-23 01:54:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-23 01:54:24 (GMT) |
commit | 9bc616cb4cd0610c21611554b50791f4d4c850e8 (patch) | |
tree | 3c167efe6c11e3cdf395e1d28b10af40929515f7 /PC | |
parent | e39cd765610c9099da3b5595186ad16223b670b0 (diff) | |
download | cpython-9bc616cb4cd0610c21611554b50791f4d4c850e8.zip cpython-9bc616cb4cd0610c21611554b50791f4d4c850e8.tar.gz cpython-9bc616cb4cd0610c21611554b50791f4d4c850e8.tar.bz2 |
gh-91061: also accept pathlib.Path for winsound.PlaySound (#91489)
Fixes #91061
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'PC')
-rw-r--r-- | PC/winsound.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/PC/winsound.c b/PC/winsound.c index fd04e1e5..65025dd 100644 --- a/PC/winsound.c +++ b/PC/winsound.c @@ -94,17 +94,25 @@ winsound_PlaySound_impl(PyObject *module, PyObject *sound, int flags) return NULL; } wsound = (wchar_t *)view.buf; + } else if (PyBytes_Check(sound)) { + PyErr_Format(PyExc_TypeError, + "'sound' must be str, os.PathLike, or None, not '%s'", + Py_TYPE(sound)->tp_name); + return NULL; } else { - if (!PyUnicode_Check(sound)) { + PyObject *obj = PyOS_FSPath(sound); + // Either <obj> is unicode/bytes/NULL, or a helpful message + // has been surfaced to the user about how they gave a non-path. + if (obj == NULL) return NULL; + if (PyBytes_Check(obj)) { PyErr_Format(PyExc_TypeError, - "'sound' must be str or None, not '%s'", - Py_TYPE(sound)->tp_name); - return NULL; - } - wsound = PyUnicode_AsWideCharString(sound, NULL); - if (wsound == NULL) { + "'sound' must resolve to str, not bytes"); + Py_DECREF(obj); return NULL; } + wsound = PyUnicode_AsWideCharString(obj, NULL); + Py_DECREF(obj); + if (wsound == NULL) return NULL; } |