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

pyshell.py: name 'sys' is not defined #73348

Closed
OOO mannequin opened this issue Jan 5, 2017 · 11 comments
Closed

pyshell.py: name 'sys' is not defined #73348

OOO mannequin opened this issue Jan 5, 2017 · 11 comments
Assignees
Labels
3.7 (EOL) end of life easy topic-IDLE type-bug An unexpected behavior, bug, or error

Comments

@OOO
Copy link
Mannequin

OOO mannequin commented Jan 5, 2017

BPO 29162
Nosy @terryjreedy, @berkerpeksag, @serhiy-storchaka, @zvyn
PRs
  • bpo-29162: IDLE: import sys before we use it on line 9 #828
  • bpo-29162: import sys before we use it on line 9 (GH-828) #833
  • 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 2017-03-27.06:01:25.761>
    created_at = <Date 2017-01-05.01:20:08.610>
    labels = ['easy', 'expert-IDLE', 'type-bug', '3.7']
    title = "pyshell.py: name 'sys' is not defined"
    updated_at = <Date 2017-04-01.20:50:22.621>
    user = 'https://bugs.python.org/OOO'

    bugs.python.org fields:

    activity = <Date 2017-04-01.20:50:22.621>
    actor = 'terry.reedy'
    assignee = 'terry.reedy'
    closed = True
    closed_date = <Date 2017-03-27.06:01:25.761>
    closer = 'berker.peksag'
    components = ['IDLE']
    creation = <Date 2017-01-05.01:20:08.610>
    creator = 'OO O'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 29162
    keywords = ['easy']
    message_count = 11.0
    messages = ['284684', '284695', '284696', '284698', '284701', '284703', '284704', '284706', '285075', '290557', '291003']
    nosy_count = 6.0
    nosy_names = ['terry.reedy', 'python-dev', 'berker.peksag', 'serhiy.storchaka', 'zvyn', 'OO O']
    pr_nums = ['828', '833']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue29162'
    versions = ['Python 3.6', 'Python 3.7']

    @OOO
    Copy link
    Mannequin Author

    OOO mannequin commented Jan 5, 2017

    Sorry for my bad English.

    line 7, 13 at pyshell.py.
    Call sys befor import sys.
    Cause name 'sys' is not defined

    @OOO OOO mannequin added the type-crash A hard crash of the interpreter, possibly with a core dump label Jan 5, 2017
    @OOO OOO mannequin assigned terryjreedy Jan 5, 2017
    @OOO OOO mannequin added the topic-IDLE label Jan 5, 2017
    @zvyn
    Copy link
    Mannequin

    zvyn mannequin commented Jan 5, 2017

    pyshell.py is not part of CPython, this is the wrong place to report a bug like this.

    @berkerpeksag
    Copy link
    Member

    I think the OP is talking about Lib/idlelib/pyshell.py. The relevant changeset is 76f831e4b806. "from tkinter import *" imports the sys module as a side-effect. OO O, did you notice this by reading the code or by using a tool like flake8?

    @berkerpeksag berkerpeksag added type-bug An unexpected behavior, bug, or error and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Jan 5, 2017
    @OOO
    Copy link
    Mannequin Author

    OOO mannequin commented Jan 5, 2017

    to msg284696 - (view):

    OK~
    Sorry I found i forget to install tkinter before I run make.
    so the "from tkinter import *" failed. ( sys not import ).

    @OOO OOO mannequin closed this as completed Jan 5, 2017
    @berkerpeksag
    Copy link
    Member

    Great, thanks for following up with us.

    @berkerpeksag
    Copy link
    Member

    I misread your comment. I think we need to add "import sys" to that file so I'm reopening this.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 5, 2017

    New changeset 52d671684342 by Terry Jan Reedy in branch '3.6':
    Issue bpo-29162: Don't depend on 'from tkinter import *' importing sys.
    https://hg.python.org/cpython/rev/52d671684342

    @terryjreedy
    Copy link
    Member

    I agree that depending on the incidental import is a bug. Tkinter could change, or I might change 'from tkinter import *' to 'from tkinter import Tk, ...' or 'import tkinter as tk'.

    Serhiy, tkinter/init.py imports enum, sys, and re under their own names, so that * imports incidentally import them into other programs. I believe it is customary for library modules to underscore stdlib imports to prevent this: "import enum as _enum", etc. But I don't remember is this is in the devguide. Do you think we should make the change to tkinter?

    @serhiy-storchaka
    Copy link
    Member

    I agree that incidental names should be eliminated from import. Could you open a new issue for this?

    @terryjreedy
    Copy link
    Member

    Reopening because I missed file=sys.__stderr__ in the print() above sys.exit ;-(. Reported by JelleZijlstra in PR.

    I wonder if there is any way to force an import to fail when testing. I could at least partly test by moving the code for import failure and that for "if TkVersion < 8.5" into functions.

    @terryjreedy
    Copy link
    Member

    The follow-up tkinter import issue is bpo-29446

    @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
    3.7 (EOL) end of life easy topic-IDLE type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants