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

PR: Use UTF-8 by default for Python files per PEP3120 #21804

Merged
merged 3 commits into from
Feb 18, 2024

Conversation

jitseniesen
Copy link
Member

Description of Changes

  • Wrote at least one-line docstrings (for any new functions)
  • Added unit test(s) covering the changes (if testable)
  • Included a screenshot or animation (if affecting the UI, see Licecap) N/A

This PR changes how Spyder determines the encoding of files opened in the editor to ensure that we follow PEP3120.

For Python files without a declaration of the form coding=xxx, use UTF-8 as encoding. For other files, we use the chardet library as before.

For the purpose of this PR, Python files are those with one of the following extensions: .py, .pyw or .ipy . This is taken from https://github.com/spyder-ide/spyder/blob/master/spyder/utils/misc.py#L211-L213.

Also add tests for the new functionality.

I made this PR as small as possible because we are close to Spyder 6, but the file "encoding.py" can probably be cleaned up a bit. Some code feels like Python 2, with the distinction between text and binary strings. The functions get_coding() and read() have parameters that do not seem to be used.

There is related discussion in issue #20510. In particular, this PR fixes the problem noted in #20510 (comment).

Issue(s) Resolved

Fixes #17807

Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

I certify the above statement is true and correct:
Jitse Niesen

@pep8speaks
Copy link

pep8speaks commented Feb 14, 2024

Hello @jitseniesen! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2024-02-18 20:28:45 UTC

Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

Thanks @jitseniesen for working on this one! I left a tiny suggestion for you, the rest looks good to me.

spyder/utils/encoding.py Outdated Show resolved Hide resolved
@ccordoba12
Copy link
Member

Also, please address the problems reported by pep8speaks above.

This PR changes how Spyder determines the encoding of files opened
in the editor to ensure that we follow PEP3120.

For Python files without a declaration of the form "coding=xxx",
use UTF-8 as encoding. For other files, we use the chardet library
as before.

For the purpose of this PR, Python files are those with one of
the following extensions: .py, .pyw or .ipy .

Also add tests for the new functionality.
This is the extension used by Python type stub files.
Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

Thanks @jitseniesen!

@ccordoba12 ccordoba12 merged commit fc0c1a7 into spyder-ide:master Feb 18, 2024
14 checks passed
@jitseniesen jitseniesen deleted the encoding branch March 18, 2024 13:33
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.

Spyder not conform PEP3120
3 participants