This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: IDLE on OS X fails with Attribute Error if no initial shell and Tk out-of-date
Type: Stage: resolved
Components: IDLE Versions: Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ned.deily Nosy List: amaury.forgeotdarc, dbackhaus, kbk, ned.deily, python-dev, roger.serwy, terry.reedy
Priority: normal Keywords: patch

Created on 2013-06-20 14:40 by dbackhaus, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
18270-27.diff terry.reedy, 2013-08-03 04:11 review
18270-27-B.diff terry.reedy, 2013-08-03 04:40 Fewer changes, should fix issue. review
Messages (9)
msg191518 - (view) Author: Dennis Backhaus (dbackhaus) Date: 2013-06-20 14:40
It just worked fine yesterday, but when I start IDLE (with and without trying to open a file at the same time) I get this error.


 Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/bin/idle", line 5, in <module>
    main()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/idlelib/PyShell.py", line 1560, in main
    shell.interp.runcommand(''.join(("print('", tkversionwarning, "')")))
AttributeError: 'NoneType' object has no attribute 'interp'
msg191523 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2013-06-20 14:55
PyShell.py, line 1541:
    if shell and cmd or script:
Does it need parentheses?
    if shell and (cmd or script):
msg191539 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2013-06-20 21:12
The problem here occurs when IDLE on OS X is launched without an initial shell window, either by setting the option in IDLE preferences or from the command line (/usr/local/bin/idle -e) *and* IDLE detects that the version of Tk in use is one of the suspect OS X versions and is attempting to warn the user with this message in the shell window:

 WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable.
 Visit http://www.python.org/download/mac/tcltk/ for current information.

Unfortunately, that doesn't work if there is no shell window.

The workaround is to follow the instructions at the above link and, if possible, install an up-to-date Tcl/Tk 8.5 from ActiveState.  If that is not possible, then launch IDLE from the command line with an initial shell window:

/usr/local/bin/idle2.7 -i

and be sure to change the preference to always launch with a shell window.
msg191544 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-06-21 00:18
In 2.7.5, the offending line is 1558, not 1560. It is clearer to me as
shell.interp.runcommand("print('%s')" % tkversionwarning)

Amaury is correct about 1541, as seen in the if block itself, but I thing the shell test should be elevated to guard all the shell-dependend actions, not just this one. See below.

To me, the problem in the cracked code and convoluted code is this:

If enable_shell (1520), call open_shell to set both flist.shell and shell but return if shell is None. But then at 1532, shell is set to flist.shell, and that can only have effect if not enable_shell (as otherwise shell *is* flist.shell due to return if None). In this case I expect flist.shell will always be None (its backup default as 292). But anyway, 1532 should be at least become an else: block for 1520.

The following lines up to 1558 all depend on shell not being None, but only one block is guarded. So I think they should all be guarded with one 'if shell:' and 'shell removed from 1541

2.7 patch attached. 3.3 code looks identical in this area, so it should have same problem and patch should apply to that also.
msg194229 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2013-08-03 02:31
Terry, your patch did not get attached.  Do you still have it?
msg194235 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-08-03 04:11
No, but I recreated it from my description and attached it. But see next message.
msg194237 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-08-03 04:40
Looking further at handling debug, startup, cmd, or script options. When any of these are set, enable_shell is also, so to reach here, shell must be true, so only the MAC test, the subject of this issue, needs protection. Smaller patch (fewer lines changed) attached.

---
Not part of this issue, but if someone can explain ...:
This this bit under "if cmd or script:" puzzles me.
        shell.interp.runcommand("""if 1:
            import sys as _sys
            _sys.argv = %r
            del _sys
            \n""" % (sys.argv,))
Since the only lasting effect it can have is on the already imported sys module, it seems to be equivalent to
        sys.argv = "%r" % (sys.argv)
And I do not know what net effect that has, if anything.
msg205873 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-12-11 00:33
New changeset 5becf8b612ee by Ned Deily in branch '2.7':
Issue #18270: Prevent possible IDLE AttributeError on OS X when no initial
http://hg.python.org/cpython/rev/5becf8b612ee

New changeset 016c64e66a9e by Ned Deily in branch '3.3':
Issue #18270: Prevent possible IDLE AttributeError on OS X when no initial
http://hg.python.org/cpython/rev/016c64e66a9e

New changeset 9d1fb265b88a by Ned Deily in branch 'default':
Issue #18270: merge from 3.3
http://hg.python.org/cpython/rev/9d1fb265b88a
msg205874 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2013-12-11 00:56
Thanks for the patch, Terry.  I've pushed a slightly modified version for release in 2.7.7, 3.3.4, and 3.4.0.
History
Date User Action Args
2022-04-11 14:57:47adminsetgithub: 62470
2014-03-07 09:35:38ned.deilylinkissue20863 superseder
2013-12-24 06:26:50ned.deilylinkissue20054 superseder
2013-12-11 00:56:56ned.deilysetstatus: open -> closed
resolution: fixed
messages: + msg205874

stage: patch review -> resolved
2013-12-11 00:33:45python-devsetnosy: + python-dev
messages: + msg205873
2013-12-09 20:33:01ned.deilylinkissue19937 superseder
2013-08-03 04:40:14terry.reedysetfiles: + 18270-27-B.diff

messages: + msg194237
2013-08-03 04:11:24terry.reedysetkeywords: + patch
files: + 18270-27.diff
messages: + msg194235

stage: needs patch -> patch review
2013-08-03 02:31:09ned.deilysetmessages: + msg194229
2013-06-21 00:18:16terry.reedysetmessages: + msg191544
2013-06-20 21:12:56ned.deilysetassignee: ned.deily

title: AttributeError: 'NoneType' object has no attribute 'interp' -> IDLE on OS X fails with Attribute Error if no initial shell and Tk out-of-date
nosy: + ned.deily
versions: + Python 3.3, Python 3.4
messages: + msg191539
stage: needs patch
2013-06-20 18:53:45serhiy.storchakasetnosy: + terry.reedy, kbk, roger.serwy
2013-06-20 14:55:02amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg191523
2013-06-20 14:40:02dbackhauscreate