Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MAINT: specify encoding in numpy/testing/_private/utils.py#31553

Merged
seberg merged 1 commit into
numpy:mainfrom
Lawson-Darrow:maint-testing-encoding-utf8
Jun 3, 2026
Merged

MAINT: specify encoding in numpy/testing/_private/utils.py#31553
seberg merged 1 commit into
numpy:mainfrom
Lawson-Darrow:maint-testing-encoding-utf8

Conversation

@Lawson-Darrow
Copy link
Copy Markdown
Contributor

PR summary

Several open() and subprocess.run(..., text=True) calls in numpy/testing/_private/utils.py omit an explicit encoding, which triggers EncodingWarning under PYTHONWARNDEFAULTENCODING=1 / python -X warn_default_encoding on Python 3.10+.

The most recent report in gh-24115 points at the subprocess.run(cmd, capture_output=True, text=True) call in this module. This PR also covers nearby open() calls that read /proc/<pid>/stat and /proc/meminfo.

All affected call sites read Linux pseudo-files or tool output that is plain ASCII, so encoding="utf-8" preserves the existing decoded result while making the behavior independent of the process locale.

This is a scoped maintenance change toward gh-24115 for the numpy/testing area. It is intended to be mechanical only, with no behavior change.

First time committer introduction

Hi, I’m Lawson. I use NumPy through research I conduct in school and other side projects. I have been looking for more OSS projects to contribute to in the machine learning space. This is my first NumPy contribution, so I tried to keep the change small and focused.

AI Disclosure

AI assisted with this PR. Tools: Claude Code (Anthropic) and OpenAI Codex. They helped identify the un-encoded open() / subprocess.run() call sites and draft the PR text. I reviewed and verified the change, understand it, and can explain it.

Thanks @jorenham reopening with the template filled in, including the AI disclosure. Apologies again for missing it the first time.

Several open() and subprocess.run() calls in numpy/testing/_private/utils.py
omit the encoding argument, which triggers EncodingWarning under
PYTHONWARNDEFAULTENCODING=1 (Python 3.10+) -- for example when downstream
projects run their test suites with that flag set (the most recent report on
numpygh-24115 points at the subprocess.run call here). These calls read ASCII data
from /proc and the output of `lscpu`, so utf-8 is the correct explicit encoding.

Addresses the numpy/testing portion of numpygh-24115.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@seberg seberg closed this Jun 3, 2026
@seberg seberg reopened this Jun 3, 2026
Copy link
Copy Markdown
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

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

Thanks, not sure it really matters much this point with 3.15 even coming around but let's get it in. (I also suspect ascii would be just as well for all of these.)

I dunno what's with circleci... I thought close/reopen would trigger it, but...

@Lawson-Darrow
Copy link
Copy Markdown
Contributor Author

Sounds good, thanks for the response! If you think its worth the merge then lets do it otherwise no hard feelings. Excited to contribute to the project and look forward to contributing more in the future!

As for the circleci idk whats going on there it was giving me trouble too.

@seberg seberg merged commit 66446be into numpy:main Jun 3, 2026
170 of 173 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.

2 participants