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

ENH: use PYTHONWARNDEFAULTENCODING=1 to fix optional encoding warnings in Python 3.10+ #24115

Open
Zac-HD opened this issue Jul 4, 2023 · 2 comments
Labels
sprintable Issue fits the time-frame and setting of a sprint

Comments

@Zac-HD
Copy link
Contributor

Zac-HD commented Jul 4, 2023

Under Python 3.11, though for some reason I haven't investigated not 3.10,

import numpy.testing

triggers the following EncodingWarning

$ python -X warn_default_encoding demo.py
numpy/testing/_private/utils.py:1251: EncodingWarning: 'encoding' argument not specified.
  output = subprocess.run(cmd, capture_output=True, text=True)

It would be great if Numpy added this to CI and fixed however many errors that turns up; with Pytest 7.4.0 and later running clean it's now reasonably practical to do so.

You may want a two-stage approach where you fix all the current cases in Numpy first (like HypothesisWorks/hypothesis#3619), and then revisit enforcing it in CI once upstream projects have cleaned up their own warnings (like HypothesisWorks/hypothesis#3691, where I hit this issue).

@mattip
Copy link
Member

mattip commented Jul 5, 2023

I see. We need to add encoding="utf-8" a bit everywhere to make that warning go away, and remove it for python 3.15+, according to PEP 686. That warning was added for python3.11, so one the 3.11+ CI runs should add the env variable.

@mattip mattip added the sprintable Issue fits the time-frame and setting of a sprint label Jul 5, 2023
@Zac-HD
Copy link
Contributor Author

Zac-HD commented Jul 5, 2023

The warning exists from Python 3.10, though there were some related small changes in 3.11.

We don't actually need to remove the encoding arguments in 3.15 - as I understand it Python will then default to using uft-8 by default, but end-users can still disable that so libraries should probably keep specifying encoding when we know which of utf-8 or locale is preferred.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sprintable Issue fits the time-frame and setting of a sprint
Projects
None yet
Development

No branches or pull requests

2 participants