classification
Title: pyflakes: remove unused imports
Type: Stage: patch review
Components: Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: barry, berker.peksag, jnoller, python-dev, r.david.murray, sbt, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2014-03-19 10:47 by vstinner, last changed 2014-03-23 18:25 by python-dev. This issue is now closed.

Files
File name Uploaded Description Edit
unused_imports.patch vstinner, 2014-03-19 10:47
issue20976_tarfile.diff berker.peksag, 2014-03-19 11:15 review
Messages (14)
msg214073 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-03-19 10:47
I ran pyflakes on Python 3.5. Attached patch removes unused imports.

Sometimes, it's tricky to decide if an import is useless or if it is part of the API.

Strange example using import to define a method!
---
class Message:
    ...
    def get_charsets(self, failobj=None):
        ...
    # I.e. def walk(self): ...
    from email.iterators import walk
---

For the email module, I moved "from quopri import decodestring as _qdecode" from Lib/email/utils.py to email submodules where it used.

I made a similar change in multiprocessing for "from subprocess import _args_from_interpreter_flags".

Since "_qdecode" and "_args_from_interpreter_flags" are private functions, I don't consider that they were part of the public API.

Removing imports might reduce the Python memory footprint and speedup the Python startup.
msg214078 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2014-03-19 11:15
Here's an alternative patch for the tarfile module.
msg214080 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-03-19 11:20
IMO issue20976_tarfile.diff is useless.
msg214135 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-03-19 20:51
LGTM. But for _qdecode you should ask RDM.
msg214152 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-03-19 23:49
I would prefer that _qdecode be left alone.
msg214186 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-03-20 08:28
New changeset f6f691ff27b9 by Victor Stinner in branch '3.4':
Issue #20976: pyflakes: Remove unused imports
http://hg.python.org/cpython/rev/f6f691ff27b9

New changeset 714002a5c1b7 by Victor Stinner in branch 'default':
(Merge 3.4) Issue #20976: pyflakes: Remove unused imports
http://hg.python.org/cpython/rev/714002a5c1b7
msg214189 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-03-20 08:29
> I would prefer that _qdecode be left alone.

Ok, I leaved these symbols unchanged in Lib/email/utils.py even if they are not used:
--
from quopri import decodestring as _qdecode
from email.encoders import _bencode, _qencode
--
msg214227 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2014-03-20 13:20
On Mar 20, 2014, at 08:29 AM, STINNER Victor wrote:

>from quopri import decodestring as _qdecode
>from email.encoders import _bencode, _qencode

AFAICT, _qdecode is only used in email/messages.py, so perhaps it's better to
import it there and remove it from utils.py?

_bencode and _qencode are imported/defined and used in encoders.py.  It
doesn't seem like utils.py or any other code uses them.

They're all non-public so why not clean it up?
msg214230 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-03-20 13:32
Well, one reason is I was afraid mailman might be using them.  So if you are cool with it, that removes that objection.

The other reason was that it seemed they were being used "from" utils on purpose, as a design thing.  I did not take the time to do a full analysis, since Victor wanted to get his patch in.

So, if you've taken a look and you think there's no reason to keep them the way they are, then I'm fine with it.
msg214232 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-03-20 13:35
Barry, David: It's up to you. I'm done with this issue, but you can drop more unused import if you want. Since I don't know well the email module, I don't want to be responsible of breaking it :-)
msg214233 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2014-03-20 13:46
On Mar 20, 2014, at 01:32 PM, R. David Murray wrote:

>Well, one reason is I was afraid mailman might be using them.  So if you are
>cool with it, that removes that objection.

Nope, neither the 2.1 or 3.0 code uses those methods AFAICT.

>The other reason was that it seemed they were being used "from" utils on
>purpose, as a design thing.  I did not take the time to do a full analysis,
>since Victor wanted to get his patch in.

I suspect it's just left over cruft from the early days of the email/mimelib
code.

>So, if you've taken a look and you think there's no reason to keep them the
>way they are, then I'm fine with it.

Do you want the honors? :)
msg214236 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-03-20 14:00
Sure.
msg214624 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-03-23 18:19
New changeset 5d645f290d6a by R David Murray in branch '3.4':
#20976: remove unneeded quopri import in email.utils.
http://hg.python.org/cpython/rev/5d645f290d6a
msg214625 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-03-23 18:25
New changeset d308c20bf2f4 by R David Murray in branch 'default':
Merge #20976: remove unneeded quopri import in email.utils.
http://hg.python.org/cpython/rev/d308c20bf2f4
History
Date User Action Args
2014-03-23 18:25:06python-devsetmessages: + msg214625
2014-03-23 18:19:32python-devsetmessages: + msg214624
2014-03-20 14:00:04r.david.murraysetmessages: + msg214236
2014-03-20 13:46:57barrysetmessages: + msg214233
2014-03-20 13:35:19vstinnersetmessages: + msg214232
2014-03-20 13:32:31r.david.murraysetmessages: + msg214230
2014-03-20 13:20:31barrysetmessages: + msg214227
2014-03-20 08:29:57vstinnersetstatus: open -> closed
resolution: fixed
2014-03-20 08:29:49vstinnersetmessages: + msg214189
2014-03-20 08:28:42python-devsetnosy: + python-dev
messages: + msg214186
2014-03-19 23:49:17r.david.murraysetmessages: + msg214152
2014-03-19 20:51:12serhiy.storchakasetmessages: + msg214135
2014-03-19 11:20:28vstinnersetmessages: + msg214080
2014-03-19 11:15:43berker.peksagsetfiles: + issue20976_tarfile.diff

nosy: + berker.peksag, serhiy.storchaka
messages: + msg214078

stage: patch review
2014-03-19 10:47:40vstinnercreate