Skip to content
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

gh-91061: also accept pathlib.Path for winsound.PlaySound #91489

Merged
merged 9 commits into from May 23, 2022

Conversation

moribellamy
Copy link
Contributor

@moribellamy moribellamy commented Apr 12, 2022

No description provided.

@moribellamy moribellamy requested a review from a team as a code owner Apr 12, 2022
@cpython-cla-bot
Copy link

cpython-cla-bot bot commented Apr 12, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

@arhadthedev
Copy link
Contributor

arhadthedev commented Apr 13, 2022

While the autolinker bot is being enhanced, here is a link so the readers of the PR can jump here via an autogenerated line back there: gh-91061.

PC/winsound.c Outdated Show resolved Hide resolved
PC/winsound.c Outdated Show resolved Hide resolved
@moribellamy
Copy link
Contributor Author

moribellamy commented May 8, 2022

@JelleZijlstra any more comments? i updated the error message since you last looked.

PC/winsound.c Outdated
@@ -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'",
Copy link
Member

@JelleZijlstra JelleZijlstra May 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor fix:

Suggested change
"'sound' must be str, os.PathLike, or None; not '%s'",
"'sound' must be str, os.PathLike, or None, not '%s'",

Bigger question: What if we have a subclass of bytes that also is a PathLike resolving to a str? How is that case handled elsewhere?

Copy link
Contributor Author

@moribellamy moribellamy May 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK the PathLike in test_winsound.py::PlaySoundTest.test_snd_filepath() (on line 129) resolves to str, so we have that covered

Copy link
Member

@JelleZijlstra JelleZijlstra May 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That one isn't a bytes subclass.

Copy link
Contributor Author

@moribellamy moribellamy May 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see. an object fitting that description would pass straight through PyOS_FSPath, without calling fspath on it first. open() would exhibit the same behavior, since open() passes a pyobject to PyOS_FSPath as well without checking for this case.

Copy link
Contributor Author

@moribellamy moribellamy May 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see _io_open_impl in _iomodule.c

Copy link
Contributor Author

@moribellamy moribellamy May 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JelleZijlstra to recap, open() would treat that kind of object by looking at the bytes object x itself, and would not try x.__fspath__(). this code, as it stands, does the same thing. what should we do?

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@moribellamy moribellamy requested a review from JelleZijlstra May 22, 2022
@JelleZijlstra JelleZijlstra self-assigned this May 23, 2022
@JelleZijlstra JelleZijlstra merged commit 9bc616c into python:main May 23, 2022
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants