classification
Title: Consistently group and sort imports within idlelib modules.
Type: enhancement Stage: resolved
Components: IDLE Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: python-dev, terry.reedy
Priority: normal Keywords: patch

Created on 2016-08-30 01:46 by terry.reedy, last changed 2016-08-31 23:37 by python-dev. This issue is now closed.

Files
File name Uploaded Description Edit
imports-27891.diff terry.reedy, 2016-08-30 08:40 review
import-27891-2.diff terry.reedy, 2016-08-31 03:37 revise 3 files, add README material review
Messages (8)
msg273892 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-08-30 01:46
PEP 8 suggests separately grouping stdlib, dependency, and local package imports.  Within idlelib, idlelib imports are treated as local package imports.  Tkinter is sometimes treated as a dependency, which makes its imports easy to notice, and I want to do this consistently.  It is conventional to sort imports within each group.  This is sometimes true now, sometimes not (even before the 3.6 renaming).

The possible danger of rearranging imports is that a line gets deleted and not pasted.  Rietveld's side-by-side diff should make this easy to detect.

This issue is about re-arranging the imports currently at the top of a file, and any module level imports that I notice elsewhere.  Dealing with delayed imports within functions and classed will be another issue, which will depend on this one.
msg273895 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-08-30 02:16
This issue includes adding the idlelib import coding standard to idlelib.README.

The delayed-import issue is #27893.

A second followup will be to stop importing tkinter modules 'as' their Py 2 names.  Change "from tkinter import font as TkFont" to "from tkinter import font" and globally replace 'TkFont' with 'tkfont'.  Do the same for messagebox and any other submodules as needed.
msg273897 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-08-30 03:07
On 2002 Sept 14, the following was merged into editor.py (then EditorWindow.py) as part of the smart indenting code added to the bottom.

import tokenize
_tokenize
del tokenize

This now would usually be written "import tokenize as _tokenize".  Stdlib modules without explicit __all__ often do this to omit stdlib modules from their public interface.  Idlelib does not do this.  Add to README import standards.  I put replaced the above with 'import tokenize' as the top where is belongs and changed all '_tokenize' to 'tokenize'.
msg273905 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-08-30 08:40
Part of previous message should be 'at the top where it belongs'.

With attached patch, each file compiles and (incomplete) tests pass.  Will examine each with side-by-side diff.  There might be artifacts from another patch left.
msg273906 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-08-30 08:44
Followup is #27892
msg273994 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-08-31 03:37
Patch 2 has minor revisions to hyperparser, mainmenu, pyshell, and adds material to README.txt.
msg274000 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-08-31 04:51
New changeset 96ac4cd43a20 by Terry Jan Reedy in branch 'default':
Issue #27891: Consistently group and sort imports within idlelib modules.
https://hg.python.org/cpython/rev/96ac4cd43a20
msg274078 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-08-31 23:37
New changeset 28ce37a2d888 by Terry Jan Reedy in branch 'default':
Issue #27891: Tweak new idlelib README entry.
https://hg.python.org/cpython/rev/28ce37a2d888
History
Date User Action Args
2016-08-31 23:37:44python-devsetmessages: + msg274078
2016-08-31 04:52:07terry.reedysetstatus: open -> closed
resolution: fixed
stage: needs patch -> resolved
2016-08-31 04:51:12python-devsetnosy: + python-dev
messages: + msg274000
2016-08-31 03:37:34terry.reedysetfiles: + import-27891-2.diff

messages: + msg273994
2016-08-30 08:44:01terry.reedysetmessages: + msg273906
2016-08-30 08:40:41terry.reedysetfiles: + imports-27891.diff
keywords: + patch
messages: + msg273905
2016-08-30 03:07:12terry.reedysetmessages: + msg273897
2016-08-30 02:16:10terry.reedysetmessages: + msg273895
2016-08-30 01:54:36terry.reedylinkissue27892 dependencies
2016-08-30 01:46:59terry.reedycreate