classification
Title: IDLE: add missing import io in iomenu.py
Type: behavior Stage: resolved
Components: IDLE Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: miss-islington, nirinA raseliarison, terry.reedy
Priority: normal Keywords: 3.8regression

Created on 2020-07-15 01:23 by nirinA raseliarison, last changed 2020-07-23 06:15 by terry.reedy. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 21512 merged terry.reedy, 2020-07-16 21:56
PR 21513 merged miss-islington, 2020-07-16 22:25
PR 21514 merged miss-islington, 2020-07-16 22:25
Messages (12)
msg373664 - (view) Author: nirinA raseliarison (nirinA raseliarison) Date: 2020-07-15 01:23
idle cannot save file with non ascii character, leading to:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib64/python3.8/tkinter/__init__.py", line 1883, in __call__
    return self.func(*args)
  File "/usr/lib64/python3.8/idlelib/multicall.py", line 176, in handler
    r = l[i](event)
  File "/usr/lib64/python3.8/idlelib/iomenu.py", line 199, in save
    else:
  File "/usr/lib64/python3.8/idlelib/iomenu.py", line 232, in writefile
    text = self.fixnewlines()
  File "/usr/lib64/python3.8/idlelib/iomenu.py", line 271, in encode
    encoded = chars.encode('ascii', 'replace')
NameError: name 'io' is not defined

just adding `import io` seems to fix this.
msg373667 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-07-15 04:43
Your suggestion is correct.

A side issue is that the line numbers in the traceback are correct but the quoted text lines from iomenu (and only iomenu) are wrong, being from the line previous.  I will have to investigate this discrepancy.

After the patch, two weeks ago, for #41158, iomenu line 199 in save is
            if self.writefile(self.filename):
line 232 in writefile is 
        chars = self.encode(text)
line 291 in encode is
        enc, _ = tokenize.detect_encoding(io.BytesIO(encoded).readline)
This is only tried if ascii encoding fails and require the addition of 'import io'.

Before I close this, I will try to add a unittest that similarly fails without the import added, as well as some others for other exit points.
msg373776 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-07-16 22:02
Łukasz, please pull this simple fix to a 3.9.0b4 and 3.8.4 regression into 3.8.5.  It disabled saving files with non-ascii chars.
msg373779 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-07-16 22:24
New changeset 38d3864efe914fda64553e2ec75c9ec15574483f by Terry Jan Reedy in branch 'master':
 bpo-41300: IDLE - save files with non-ascii chars  (GH-21512)
https://github.com/python/cpython/commit/38d3864efe914fda64553e2ec75c9ec15574483f
msg373782 - (view) Author: miss-islington (miss-islington) Date: 2020-07-16 22:42
New changeset 5a7aa280457423b97512810d6d9baac37f99fbf4 by Miss Islington (bot) in branch '3.9':
bpo-41300: IDLE - save files with non-ascii chars  (GH-21512)
https://github.com/python/cpython/commit/5a7aa280457423b97512810d6d9baac37f99fbf4
msg373783 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-07-16 22:47
New changeset ffeb9202540c07d384f82ff3ab86c37c1433283a by Miss Islington (bot) in branch '3.8':
[3.8] bpo-41300: IDLE - save files with non-ascii chars  (GH-21512)
https://github.com/python/cpython/commit/ffeb9202540c07d384f82ff3ab86c37c1433283a
msg373784 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-07-16 22:51
Łukasz, Please cherry-pick the 3.8 backport,  ffeb920, as it has a 3.8-specific fixup to idlelib/NEWS.txt.

I verified the bug and fix on Windows.  I am leaving this open to add automated tests.
msg373815 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-07-17 10:52
Problem also reported on #41319
msg373820 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-07-17 11:08
#41319 should be closed as a duplicate, but site will not currently allow me to do so.
msg374019 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2020-07-20 17:19
Released.
msg374052 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-07-21 04:25
The fix is in both 3.8.5 and 3.9.0b5, both released today.
"print('eyes ∢∢ snake 🐍')", for instance, in the editor, can be saved and run.  (Note that astral chars like the snake disrupt editing a bit, but once there, can be saved and will print.

Łukasz, thanks for getting this in.  I am leaving this open to add tests, but will remove you as nosy.
msg374124 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-07-23 06:15
#41373 is about another issue with the new iomenu code.  I will close this and add tests there.
History
Date User Action Args
2020-07-23 06:15:05terry.reedysetstatus: open -> closed
versions: + Python 3.5, - Python 3.8, Python 3.9, Python 3.10
messages: + msg374124

resolution: fixed
stage: test needed -> resolved
2020-07-21 04:25:31terry.reedysetnosy: - lukasz.langa
2020-07-21 04:25:13terry.reedysetpriority: critical -> normal

messages: + msg374052
2020-07-20 17:19:31lukasz.langasetpriority: release blocker -> critical

messages: + msg374019
2020-07-17 22:00:59terry.reedylinkissue41329 superseder
2020-07-17 11:10:00terry.reedylinkissue41319 superseder
2020-07-17 11:08:53terry.reedysetmessages: + msg373820
2020-07-17 10:52:46terry.reedysetmessages: + msg373815
2020-07-16 22:51:54terry.reedysetkeywords: - patch

messages: + msg373784
stage: patch review -> test needed
2020-07-16 22:47:56terry.reedysetmessages: + msg373783
2020-07-16 22:42:12miss-islingtonsetmessages: + msg373782
2020-07-16 22:25:31miss-islingtonsetpull_requests: + pull_request20649
2020-07-16 22:25:23miss-islingtonsetkeywords: + patch
nosy: + miss-islington

pull_requests: + pull_request20648
stage: test needed -> patch review
2020-07-16 22:24:56terry.reedysetmessages: + msg373779
2020-07-16 22:02:03terry.reedysetpriority: normal -> release blocker

versions: + Python 3.8, Python 3.9
keywords: + 3.8regression, - patch
nosy: + lukasz.langa

messages: + msg373776
stage: patch review -> test needed
2020-07-16 21:56:03terry.reedysetkeywords: + patch
stage: test needed -> patch review
pull_requests: + pull_request20647
2020-07-15 04:43:51terry.reedysetversions: + Python 3.10
title: IDLE: missing import io in iomenu.py -> IDLE: add missing import io in iomenu.py
messages: + msg373667

type: behavior
stage: test needed
2020-07-15 01:23:31nirinA raseliarisoncreate