Skip to content

GH-128520: pathlib ABCs: raise text encoding warnings at correct stack level #133051

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

Merged
merged 2 commits into from
Apr 28, 2025

Conversation

barneygale
Copy link
Contributor

@barneygale barneygale commented Apr 27, 2025

Ensure that warnings about unspecified text encodings are emitted from ReadablePath.read_text(), WritablePath.write_text() and magic_open() with the correct stack level set.

These classes/functions are still private, so there's no public change of behaviour.

Ensure that warnings about unspecified text encodings are emitted from
`ReadablePath.read_text()`, `WritablePath.write_text()` and `magic_open()`
with the correct stack level set.
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

Looks good. Do we run any tests/buildbots with warn_default_encoding on?

An alternative way to write the tests would be to run a subprocess that has the flag on.

@barneygale
Copy link
Contributor Author

barneygale commented Apr 28, 2025

Thanks!

I can't see any indication that any build bots enable warn_default_encoding, but I'm not sure how to confirm!

FWIW, when I backport this to the pathlib-abc pypi package, I'll add PYTHONWARNDEFAULTENCODING = 1 to tox.ini. There's a similar setup in the zipp package and the zipfile.Path tests

@JelleZijlstra
Copy link
Member

I'd prefer if these tests are exercised in some way in CPython's own CI but up to you if you prefer a different approach; feel free to merge as is.

@barneygale
Copy link
Contributor Author

Thanks Jelle.

I'll get these tests running in CPython CI in a follow-up PR, because I suspect the same fix will be useful in the zipfile.Path tests, and that'll need to land upstream in zipp first.

@barneygale barneygale merged commit fbffd70 into python:main Apr 28, 2025
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants