classification
Title: pyshell.py: name 'sys' is not defined
Type: behavior Stage: resolved
Components: IDLE Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: OO O, berker.peksag, python-dev, serhiy.storchaka, terry.reedy, zvyn
Priority: normal Keywords: easy

Created on 2017-01-05 01:20 by OO O, last changed 2017-04-01 20:50 by terry.reedy. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 828 merged Jelle Zijlstra, 2017-03-27 02:13
PR 833 merged Mariatta, 2017-03-27 02:25
Messages (11)
msg284684 - (view) Author: OO O (OO O) Date: 2017-01-05 01:20
Sorry for my bad English.

line 7, 13 at pyshell.py.
Call sys befor import sys.
Cause name 'sys' is not defined
msg284695 - (view) Author: Milan Oberkirch (zvyn) * Date: 2017-01-05 03:18
pyshell.py is not part of CPython, this is the wrong place to report a bug like this.
msg284696 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-01-05 03:27
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?
msg284698 - (view) Author: OO O (OO O) Date: 2017-01-05 03:35
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 ).
msg284701 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-01-05 03:56
Great, thanks for following up with us.
msg284703 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-01-05 03:59
I misread your comment. I think we need to add "import sys" to that file so I'm reopening this.
msg284704 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-01-05 04:18
New changeset 52d671684342 by Terry Jan Reedy in branch '3.6':
Issue #29162: Don't depend on 'from tkinter import *' importing sys.
https://hg.python.org/cpython/rev/52d671684342
msg284706 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-01-05 04:28
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?
msg285075 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-01-09 21:22
I agree that incidental names should be eliminated from import. Could you open a new issue for this?
msg290557 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-03-27 02:04
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.
msg291003 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-04-01 20:50
The follow-up tkinter import issue is #29446
History
Date User Action Args
2017-04-01 20:50:22terry.reedysetmessages: + msg291003
2017-03-27 06:01:25berker.peksagsetstatus: open -> closed
resolution: fixed
2017-03-27 02:25:13Mariattasetpull_requests: + pull_request736
2017-03-27 02:13:41Jelle Zijlstrasetpull_requests: + pull_request735
2017-03-27 02:04:02terry.reedysetstatus: closed -> open
resolution: fixed -> (no value)
messages: + msg290557
2017-01-09 21:22:31serhiy.storchakasetmessages: + msg285075
2017-01-05 04:28:20terry.reedysetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg284706

resolution: fixed
stage: needs patch -> resolved
2017-01-05 04:18:30python-devsetnosy: + python-dev
messages: + msg284704
2017-01-05 03:59:53berker.peksagsetstatus: closed -> open
versions: + Python 3.7
messages: + msg284703

keywords: + easy
resolution: not a bug -> (no value)
stage: resolved -> needs patch
2017-01-05 03:56:20berker.peksagsetresolution: not a bug
messages: + msg284701
stage: resolved
2017-01-05 03:35:25OO Osetstatus: open -> closed

messages: + msg284698
2017-01-05 03:27:17berker.peksagsettype: crash -> behavior

messages: + msg284696
nosy: + berker.peksag
2017-01-05 03:18:24zvynsetnosy: + zvyn
messages: + msg284695
2017-01-05 01:20:08OO Ocreate