[Python-Dev] Think a dead import finding script would be handy?

2008-08-17 Thread Brett Cannon
After Christian mentioned how we could speed up interpreter start-up
by removing some dead imports he found, I decided to write up a quick
script that generates the AST for a source file and (very roughly)
tries to find imports that are never used. People think it's worth
tossing into Tools, even if it is kind of rough? Otherwise I might
toss it into the sandbox or make a quick Google code project out of
it.

Regardless, one interesting side-effect of the script is that beyond
finding some extraneous imports in various places, it also found some
holes in __all__. I have the script look for the definition of __all__
and consider an import used if it is listed there.

-Brett
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Think a dead import finding script would be handy?

2008-08-17 Thread Georg Brandl
Brett Cannon schrieb:
 After Christian mentioned how we could speed up interpreter start-up
 by removing some dead imports he found, I decided to write up a quick
 script that generates the AST for a source file and (very roughly)
 tries to find imports that are never used. People think it's worth
 tossing into Tools, even if it is kind of rough? Otherwise I might
 toss it into the sandbox or make a quick Google code project out of
 it.
 
 Regardless, one interesting side-effect of the script is that beyond
 finding some extraneous imports in various places, it also found some
 holes in __all__. I have the script look for the definition of __all__
 and consider an import used if it is listed there.

pylint already finds unused imports. It finds tons of other, relatively
useless, stuff in the default configuration, but I'm sure it can be
coaxed into only showing unused imports too.

Georg

-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Think a dead import finding script would be handy?

2008-08-17 Thread Christian Heimes

Brett Cannon wrote:

After Christian mentioned how we could speed up interpreter start-up
by removing some dead imports he found, I decided to write up a quick
script that generates the AST for a source file and (very roughly)
tries to find imports that are never used. People think it's worth
tossing into Tools, even if it is kind of rough? Otherwise I might
toss it into the sandbox or make a quick Google code project out of
it.

Regardless, one interesting side-effect of the script is that beyond
finding some extraneous imports in various places, it also found some
holes in __all__. I have the script look for the definition of __all__
and consider an import used if it is listed there.


Zope 3 has various tools for sorting imports or checking for unused 
imports. See http://svn.zope.org/Zope3/trunk/utilities/



Python 3.0 currently imports 25 modules on startup, Python 2.6 just 14:

./python -S -c import sys; print(list(sorted(sys.modules)), 
len(sys.modules))


['__main__', '_abcoll', '_codecs', '_fileio', '_thread', '_weakref', 
'_weakrefset', 'abc', 'builtins', 'codecs', 'copyreg', 'encodings', 
'encodings.aliases', 'encodings.latin_1', 'encodings.utf_8', 'errno', 
'genericpath', 'io', 'os', 'os.path', 'posix', 'posixpath', 'signal', 
'stat', 'sys', 'zipimport'] 26


_abcoll
  os.envirion uses _abcoll.MutableMapping

_weakref + _weakrefset
  imported for abc

abc
  imported for io.IOBase

copyreg
  imported by os to register some pickle handlers.
  Could be removed by placing the code into copyreg instead.

encodings.*
  imported early to avoid various bootstrapping issues (IIRC)

encodings.aliases:
  Could be removing by delaying the import until search_function()
  is called the first time

errno, genericpath, posix, posixpath, stat:
  import by os and os.path

stat:
  Could probably be replaced by a simple and faster C implementation
  in posixmodule.c to spare the import

signal:
  I'm not sure why the module is loaded at all.

I think we can get rid of copyreg and encodings.aliases easily.

Christian
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Think a dead import finding script would be handy?

2008-08-17 Thread Brett Cannon
On Sun, Aug 17, 2008 at 1:40 PM, Georg Brandl [EMAIL PROTECTED] wrote:
 Brett Cannon schrieb:
 After Christian mentioned how we could speed up interpreter start-up
 by removing some dead imports he found, I decided to write up a quick
 script that generates the AST for a source file and (very roughly)
 tries to find imports that are never used. People think it's worth
 tossing into Tools, even if it is kind of rough? Otherwise I might
 toss it into the sandbox or make a quick Google code project out of
 it.

 Regardless, one interesting side-effect of the script is that beyond
 finding some extraneous imports in various places, it also found some
 holes in __all__. I have the script look for the definition of __all__
 and consider an import used if it is listed there.

 pylint already finds unused imports. It finds tons of other, relatively
 useless, stuff in the default configuration, but I'm sure it can be
 coaxed into only showing unused imports too.


Does anyone ever run pylint over the stdlib on occasion?

-Brett
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Think a dead import finding script would be handy?

2008-08-17 Thread Jean-Paul Calderone

On Sun, 17 Aug 2008 15:04:58 -0700, Brett Cannon [EMAIL PROTECTED] wrote:

On Sun, Aug 17, 2008 at 1:40 PM, Georg Brandl [EMAIL PROTECTED] wrote:

Brett Cannon schrieb:

After Christian mentioned how we could speed up interpreter start-up
by removing some dead imports he found, I decided to write up a quick
script that generates the AST for a source file and (very roughly)
tries to find imports that are never used. People think it's worth
tossing into Tools, even if it is kind of rough? Otherwise I might
toss it into the sandbox or make a quick Google code project out of
it.

Regardless, one interesting side-effect of the script is that beyond
finding some extraneous imports in various places, it also found some
holes in __all__. I have the script look for the definition of __all__
and consider an import used if it is listed there.


pylint already finds unused imports. It finds tons of other, relatively
useless, stuff in the default configuration, but I'm sure it can be
coaxed into only showing unused imports too.



Does anyone ever run pylint over the stdlib on occasion?



Buildbot includes a pyflakes step.

Jean-Paul
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Think a dead import finding script would be handy?

2008-08-17 Thread Neal Norwitz
On Sun, Aug 17, 2008 at 3:04 PM, Brett Cannon [EMAIL PROTECTED] wrote:
 On Sun, Aug 17, 2008 at 1:40 PM, Georg Brandl [EMAIL PROTECTED] wrote:
 Brett Cannon schrieb:
 After Christian mentioned how we could speed up interpreter start-up
 by removing some dead imports he found, I decided to write up a quick
 script that generates the AST for a source file and (very roughly)
 tries to find imports that are never used. People think it's worth
 tossing into Tools, even if it is kind of rough? Otherwise I might
 toss it into the sandbox or make a quick Google code project out of
 it.

 Regardless, one interesting side-effect of the script is that beyond
 finding some extraneous imports in various places, it also found some
 holes in __all__. I have the script look for the definition of __all__
 and consider an import used if it is listed there.

 pylint already finds unused imports. It finds tons of other, relatively
 useless, stuff in the default configuration, but I'm sure it can be
 coaxed into only showing unused imports too.


 Does anyone ever run pylint over the stdlib on occasion?

I usually run pychecker (which also finds unused imports and a whole
lot more) before releases.  I typically wait for things to settle down
(ie, well into beta).

n
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com