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

Add encoding parameter to {read,write}_text (PEP 597). #5

Open
liborjelinek opened this issue Nov 3, 2023 · 2 comments
Open

Add encoding parameter to {read,write}_text (PEP 597). #5

liborjelinek opened this issue Nov 3, 2023 · 2 comments

Comments

@liborjelinek
Copy link
Collaborator

liborjelinek commented Nov 3, 2023

(Migrated from https://gitlab.com/documatt/sphinx-reredirects/-/merge_requests/11. Requested 3 months ago by Anderson Bravalheri @abravalheri.)

With the introduction of PEP 597, relying on the default value of
encoding for functions that read/write files is no longer recommended,
and developers have been incentivised to run tests using
PYTHONWARNDEFAULTENCODING=1 to identify when the encoding argument
is not given.

As a result, when PYTHONWARNDEFAULTENCODING=1 is set on the CI
environment responsible for building the docs, sphinx_reredirects
will emit a EncodingWarning: 'encoding' argument not specified.

The objective of this change is to comply with the PEP's recommendations
and avoid the EncodingWarning from being emitted.

(Proposed changes: https://gitlab.com/documatt/sphinx-reredirects/-/merge_requests/11/diffs?commit_id=93dd8ebe5afcbbd57aa3e70752687b45f319d355.)

@DimitriPapadopoulos
Copy link

Good idea, this should address warnings that appear in CI jobs such as https://github.com/pypa/setuptools/actions/runs/9179511894/job/25241806696:

/home/runner/work/setuptools/setuptools/.tox/docs/lib/python3.12/site-packages/sphinx_reredirects/__init__.py:151: EncodingWarning: 'encoding' argument not specified
  at_path.write_text(content)

@DimitriPapadopoulos
Copy link

For what it's worth, there's a Pylint/ruff rule for that: PLW1514

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

No branches or pull requests

2 participants