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

IDLE: add missing import io in iomenu.py #85472

Closed
nirinAraseliarison mannequin opened this issue Jul 15, 2020 · 12 comments
Closed

IDLE: add missing import io in iomenu.py #85472

nirinAraseliarison mannequin opened this issue Jul 15, 2020 · 12 comments
Assignees
Labels
topic-IDLE type-bug An unexpected behavior, bug, or error

Comments

@nirinAraseliarison
Copy link
Mannequin

nirinAraseliarison mannequin commented Jul 15, 2020

BPO 41300
Nosy @terryjreedy, @miss-islington
PRs
  • bpo-41300: IDLE - save files with non-ascii chars  #21512
  • [3.9] bpo-41300: IDLE - save files with non-ascii chars (GH-21512) #21513
  • [3.8] bpo-41300: IDLE - save files with non-ascii chars (GH-21512) #21514
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/terryjreedy'
    closed_at = <Date 2020-07-23.06:15:05.985>
    created_at = <Date 2020-07-15.01:23:31.394>
    labels = ['expert-IDLE', 'type-bug']
    title = 'IDLE: add missing import io in iomenu.py'
    updated_at = <Date 2020-07-23.06:15:05.982>
    user = 'https://bugs.python.org/nirinAraseliarison'

    bugs.python.org fields:

    activity = <Date 2020-07-23.06:15:05.982>
    actor = 'terry.reedy'
    assignee = 'terry.reedy'
    closed = True
    closed_date = <Date 2020-07-23.06:15:05.985>
    closer = 'terry.reedy'
    components = ['IDLE']
    creation = <Date 2020-07-15.01:23:31.394>
    creator = 'nirinA raseliarison'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41300
    keywords = ['3.8regression']
    message_count = 12.0
    messages = ['373664', '373667', '373776', '373779', '373782', '373783', '373784', '373815', '373820', '374019', '374052', '374124']
    nosy_count = 3.0
    nosy_names = ['terry.reedy', 'miss-islington', 'nirinA raseliarison']
    pr_nums = ['21512', '21513', '21514']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue41300'
    versions = ['Python 3.5']

    @nirinAraseliarison
    Copy link
    Mannequin Author

    nirinAraseliarison mannequin commented Jul 15, 2020

    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.

    @terryjreedy
    Copy link
    Member

    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 bpo-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.

    @terryjreedy terryjreedy added the 3.10 only security fixes label Jul 15, 2020
    @terryjreedy terryjreedy changed the title IDLE: missing import io in iomenu.py IDLE: add missing import io in iomenu.py Jul 15, 2020
    @terryjreedy terryjreedy added type-bug An unexpected behavior, bug, or error 3.10 only security fixes labels Jul 15, 2020
    @terryjreedy terryjreedy changed the title IDLE: missing import io in iomenu.py IDLE: add missing import io in iomenu.py Jul 15, 2020
    @terryjreedy terryjreedy added the type-bug An unexpected behavior, bug, or error label Jul 15, 2020
    @terryjreedy
    Copy link
    Member

    Ł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.

    @terryjreedy terryjreedy added 3.8 only security fixes 3.9 only security fixes release-blocker labels Jul 16, 2020
    @terryjreedy
    Copy link
    Member

    New changeset 38d3864 by Terry Jan Reedy in branch 'master':
    bpo-41300: IDLE - save files with non-ascii chars (GH-21512)
    38d3864

    @miss-islington
    Copy link
    Contributor

    New changeset 5a7aa28 by Miss Islington (bot) in branch '3.9':
    bpo-41300: IDLE - save files with non-ascii chars (GH-21512)
    5a7aa28

    @terryjreedy
    Copy link
    Member

    New changeset ffeb920 by Miss Islington (bot) in branch '3.8':
    [3.8] bpo-41300: IDLE - save files with non-ascii chars (GH-21512)
    ffeb920

    @terryjreedy
    Copy link
    Member

    Ł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.

    @terryjreedy
    Copy link
    Member

    Problem also reported on bpo-41319

    @terryjreedy
    Copy link
    Member

    bpo-41319 should be closed as a duplicate, but site will not currently allow me to do so.

    @ambv
    Copy link
    Contributor

    ambv commented Jul 20, 2020

    Released.

    @terryjreedy
    Copy link
    Member

    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.

    @terryjreedy
    Copy link
    Member

    bpo-41373 is about another issue with the new iomenu code. I will close this and add tests there.

    @terryjreedy terryjreedy removed 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes labels Jul 23, 2020
    @terryjreedy terryjreedy removed 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes labels Jul 23, 2020
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-IDLE type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants