Skip to content

[3.15] gh-153319: Read turtledemo scripts with the source file's own encoding (GH-153321) - #157872

Open
miss-islington wants to merge 1 commit into
python:3.15from
miss-islington:backport-de0d976-3.15
Open

miss-islington wants to merge 1 commit into
python:3.15from
miss-islington:backport-de0d976-3.15

Conversation

@miss-islington

@miss-islington miss-islington commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Stop using locale default encoding. All stdlib .py files (except for testing) are utf-8 encoded.


(cherry picked from commit de0d976)

Co-authored-by: tonghuaroot (童话) tonghuaroot@gmail.com
Co-authored-by: Serhiy Storchaka storchaka@gmail.com
Co-authored-by: Terry Jan Reedy tjreedy@udel.edu

…ncoding (pythonGH-153321)

The demo viewer read each script with open() and no encoding argument, i.e. the locale default encoding. That emits an EncodingWarning under -X warn_default_encoding and can mis-decode a script on a non-UTF-8 locale. Read the source with tokenize.open() instead, which decodes using the encoding detected from the file (its coding cookie, else UTF-8), matching how Python read the module when it was imported just above.

* pythongh-153319: Read turtledemo scripts as UTF-8

Per review, open the demo scripts with encoding='utf-8' instead of
tokenize.open(); the scripts are UTF-8.

---------
(cherry picked from commit de0d976)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
@hugovk

hugovk commented Sep 21, 2026

Copy link
Copy Markdown
Member

Left question about this PR here: #153321 (comment)

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.

4 participants