classification
Title: Remove unused imports in standard library
Type: Stage: resolved
Components: Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, miss-islington, rhettinger, terry.reedy, thatiparthy
Priority: normal Keywords: patch

Created on 2018-11-09 19:09 by thatiparthy, last changed 2018-11-17 07:03 by terry.reedy. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 10438 merged thatiparthy, 2018-11-09 23:41
PR 10445 merged thatiparthy, 2018-11-10 04:36
PR 10446 merged thatiparthy, 2018-11-10 06:22
PR 10447 merged miss-islington, 2018-11-10 06:45
PR 10448 merged miss-islington, 2018-11-10 06:46
PR 10450 merged thatiparthy, 2018-11-10 08:10
PR 10561 merged thatiparthy, 2018-11-16 05:39
PR 10573 merged thatiparthy, 2018-11-16 14:15
PR 10582 merged miss-islington, 2018-11-17 06:38
PR 10583 merged miss-islington, 2018-11-17 06:38
Messages (14)
msg329548 - (view) Author: Srinivas Reddy Thatiparthy(శ్రీనివాస్ రెడ్డి తాటిపర్తి) (thatiparthy) * Date: 2018-11-09 19:09
Please find the modules where we need to remove.


codecs.py:1105:5: F401 'encodings' imported but unused
code.py:298:13: F401 'readline' imported but unused
platform.py:118:1: F401 'warnings' imported but unused
platform.py:509:9: F401 'java.lang' imported but unused
pstats.py:562:9: F401 'readline' imported but unused
shutil.py:13:1: F401 'io' imported but unused
site.py:409:13: F401 'rlcompleter' imported but unused
site.py:511:13: F401 'sitecustomize' imported but unused
site.py:531:13: F401 'usercustomize' imported but unused
trace.py:54:1: F401 're' imported but unused
typing.py:21:1: F401 'abc' imported but unused


I was just wondering that as a community, do we recommend this practice of cleaning up Or just we keep as is inorder to NOT to break accidental imports?
msg329553 - (view) Author: Srinivas Reddy Thatiparthy(శ్రీనివాస్ రెడ్డి తాటిపర్తి) (thatiparthy) * Date: 2018-11-09 20:11
I have raised a partial PR  here  - https://github.com/python/cpython/pull/10438;  if it is merged please take up the rest of the changes mentioned in the issue description.
msg329563 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-11-09 22:41
I think we can remove these in 3.8. My understanding of the policy (which I cannot find: the search terms are too generic) is that if a module defines __all__, and the symbol we want to remove isn't in it, then we can remove the symbol in the next feature release without requiring a deprecation period.

If a module doesn't define __all__, then we need a deprecation period in order to remove a symbol, unless the symbol is a module, and then we can just remove it in the next feature release.
msg329564 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-11-09 22:42
Let me restate that: I think we can remove these in 3.8 if they're not in the module's __all__. I haven't checked that, although it would surprise me if any of them were in __all__.
msg329567 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-11-09 23:15
There's a few that should be discussed with the module maintainers first.  A patch for IDLE should go through Terry Reedy.  The "java.lang" in platform isn't a normal import and may have something to do with Jython.  The "abc" in typing.py might be there for a reason, so ask Guido before zapping it.  It's also possible that "encodings" might be in codecs for a reason as well, but I'm not sure who you should check with. 

I'm not sure about readline, rlcompleter, sitecustomize, and usercustomize. I think think those imports may be there for their side-effects.  Just importing them may suffice to enable some behavior, so be careful with these.
msg329597 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-11-10 06:45
New changeset 43a74abb3a87092a7fd6c71042eafb977d70d8e0 by Terry Jan Reedy (Srinivas  Thatiparthy (శ్రీనివాస్  తాటిపర్తి)) in branch 'master':
bpo-35202: Remove unused imports in idlelib (GH-10438)
https://github.com/python/cpython/commit/43a74abb3a87092a7fd6c71042eafb977d70d8e0
msg329598 - (view) Author: miss-islington (miss-islington) Date: 2018-11-10 07:06
New changeset 2847ccae4687cb43334d87d86fb6c11cb14218f5 by Miss Islington (bot) in branch '3.7':
bpo-35202: Remove unused imports in idlelib (GH-10438)
https://github.com/python/cpython/commit/2847ccae4687cb43334d87d86fb6c11cb14218f5
msg329599 - (view) Author: miss-islington (miss-islington) Date: 2018-11-10 07:08
New changeset 2903b0fd38a65e16ddafae7754ed5d605fea68ff by Miss Islington (bot) in branch '3.6':
bpo-35202: Remove unused imports in idlelib (GH-10438)
https://github.com/python/cpython/commit/2903b0fd38a65e16ddafae7754ed5d605fea68ff
msg329603 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-11-10 08:02
Srinivas, if you thing the issue is finished, please close it.  Otherwise say something about what is left to do.
msg329604 - (view) Author: Srinivas Reddy Thatiparthy(శ్రీనివాస్ రెడ్డి తాటిపర్తి) (thatiparthy) * Date: 2018-11-10 08:20
I have raised one more PR; I think i am done with this issue. People who are interested can take up from here. ,

For the record, following are some filters to search;

Query to find unused imports
----------------------------------

find . -type f -name \*.py -print  | xargs flake8 | grep F401
----------------------------------

Search query 
------------------------------------
grep -v warnings | grep -v "\.\*" | grep -v tkinter | grep -v sysconfig | grep -v readline | grep -v py3_test_grammar.py  | grep -v java | grep -v rlcompleter | grep -v sitecustomize | grep -v __all__ | grep -v test_importlib | grep -v async | grep -v test_future | grep -v circular_import | grep -v dataclasses
------------------------------------
msg329984 - (view) Author: Srinivas Reddy Thatiparthy(శ్రీనివాస్ రెడ్డి తాటిపర్తి) (thatiparthy) * Date: 2018-11-16 09:42
With the current PR, i think i removed all unused imports in Lib folder.
msg330024 - (view) Author: miss-islington (miss-islington) Date: 2018-11-17 06:48
New changeset 3a600d224c1e1106756cc71639232ae1acae45bd by Miss Islington (bot) in branch '3.7':
bpo-35202: Remove more unused imports in idlelib (GH-10573)
https://github.com/python/cpython/commit/3a600d224c1e1106756cc71639232ae1acae45bd
msg330025 - (view) Author: miss-islington (miss-islington) Date: 2018-11-17 07:00
New changeset 8d816f74d7673c836b16e4423fed0ec6ee510290 by Miss Islington (bot) in branch '3.6':
bpo-35202: Remove more unused imports in idlelib (GH-10573)
https://github.com/python/cpython/commit/8d816f74d7673c836b16e4423fed0ec6ee510290
msg330026 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-11-17 07:03
Thank you for the cleanup.
History
Date User Action Args
2018-11-17 07:03:32terry.reedysetstatus: open -> closed
resolution: fixed
messages: + msg330026

stage: patch review -> resolved
2018-11-17 07:00:35miss-islingtonsetmessages: + msg330025
2018-11-17 06:48:45miss-islingtonsetmessages: + msg330024
2018-11-17 06:38:23miss-islingtonsetpull_requests: + pull_request9828
2018-11-17 06:38:13miss-islingtonsetpull_requests: + pull_request9827
2018-11-16 14:15:05thatiparthysetpull_requests: + pull_request9821
2018-11-16 09:42:49thatiparthysetmessages: + msg329984
2018-11-16 05:39:35thatiparthysetpull_requests: + pull_request9807
2018-11-10 08:20:08thatiparthysetmessages: + msg329604
2018-11-10 08:10:40thatiparthysetpull_requests: + pull_request9725
2018-11-10 08:02:39terry.reedysetmessages: + msg329603
2018-11-10 07:08:08miss-islingtonsetmessages: + msg329599
2018-11-10 07:06:27miss-islingtonsetnosy: + miss-islington
messages: + msg329598
2018-11-10 06:46:00miss-islingtonsetpull_requests: + pull_request9723
2018-11-10 06:45:50miss-islingtonsetpull_requests: + pull_request9722
2018-11-10 06:45:35terry.reedysetmessages: + msg329597
2018-11-10 06:22:41thatiparthysetpull_requests: + pull_request9721
2018-11-10 04:36:26thatiparthysetpull_requests: + pull_request9720
2018-11-10 01:28:45gvanrossumsetnosy: - gvanrossum
2018-11-09 23:41:36thatiparthysetpull_requests: + pull_request9715
2018-11-09 23:15:49rhettingersetnosy: + gvanrossum, terry.reedy, rhettinger
messages: + msg329567
2018-11-09 22:42:39eric.smithsetmessages: + msg329564
2018-11-09 22:41:32eric.smithsetnosy: + eric.smith

messages: + msg329563
versions: + Python 3.8
2018-11-09 20:11:28thatiparthysetmessages: + msg329553
2018-11-09 20:10:25thatiparthysetpull_requests: - pull_request9712
2018-11-09 19:10:32thatiparthysetkeywords: + patch
stage: patch review
pull_requests: + pull_request9712
2018-11-09 19:09:12thatiparthycreate