Re: [Zope3-Users] Utility for removing unneeded import statements

2007-06-05 Thread Adam Groszer
Hello Hermann,

Z3 has an importchecker:

Import checker

This utility finds unused imports in Python modules.  Its output is
grep-like and thus emacs-friendly.
...

Althought pyflakes works for me better.
http://www.divmod.org/projects/pyflakes

Tuesday, June 5, 2007, 12:50:40 PM, you wrote:

 Hi,
 During development and especially refactoring, I'm often confronted with
 cleaning up import statements.

 Missing imports are reported by Python, however, unneeded imports are not. I
 don't know if unneded imports are a performance issue, nevertheless it
 probably makes sense to clean them up from time to time.

 Therefore I wonder if there's some tool that can automatically check if an
 import is needed or not. Probably this is easy to write, but perhaps somebody
 has already done so?

 What would be nice, would also be a tool that crawls through a python package
 and also checks any missing imports and reports all of them at once. When I
 refactor code, I often have to restart zope3 over and over, only due to
 missing import statements.

 Best Regards,
 Hermann



-- 
Best regards,
 Adammailto:[EMAIL PROTECTED]
--
Quote of the day:
Everything comes to him who waits, among other things, death.  -  Francis 
Bradley

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


RE: [Zope3-Users] Utility for removing unneeded import statements

2007-06-05 Thread Doyon, Jean-Francois
You may want to look into PyLint:

http://www.logilab.org/857

Or PyChecker:

http://pychecker.sourceforge.net/

I use PyLint through PyDev/Eclipse, and it's a godsend ...

J.F. 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Hermann Himmelbauer
Sent: June 5, 2007 06:51
To: zope3-users@zope.org
Subject: [Zope3-Users] Utility for removing unneeded import statements

Hi,
During development and especially refactoring, I'm often confronted with
cleaning up import statements.

Missing imports are reported by Python, however, unneeded imports are
not. I don't know if unneded imports are a performance issue,
nevertheless it probably makes sense to clean them up from time to time.

Therefore I wonder if there's some tool that can automatically check if
an import is needed or not. Probably this is easy to write, but perhaps
somebody has already done so?

What would be nice, would also be a tool that crawls through a python
package and also checks any missing imports and reports all of them at
once. When I refactor code, I often have to restart zope3 over and over,
only due to missing import statements.

Best Regards,
Hermann

--
[EMAIL PROTECTED]
GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Utility for removing unneeded import statements

2007-06-05 Thread Martijn Pieters

On 6/5/07, Doyon, Jean-Francois [EMAIL PROTECTED] wrote:

You may want to look into PyLint:

http://www.logilab.org/857

Or PyChecker:

http://pychecker.sourceforge.net/


Or use PyFlakes:

 http://www.divmod.org/projects/pyflakes

which doesn't execute code (like PyChecker does).

--
Martijn Pieters
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Utility for removing unneeded import statements

2007-06-05 Thread Marius Gedminas
On Tue, Jun 05, 2007 at 12:59:32PM +0200, Adam Groszer wrote:
 Tuesday, June 5, 2007, 12:50:40 PM, Hermann wrote:
  During development and especially refactoring, I'm often confronted with
  cleaning up import statements.
 
  Missing imports are reported by Python, however, unneeded imports are not. I
  don't know if unneded imports are a performance issue, nevertheless it
  probably makes sense to clean them up from time to time.
 
  Therefore I wonder if there's some tool that can automatically check if an
  import is needed or not. Probably this is easy to write, but perhaps 
  somebody
  has already done so?
 
  What would be nice, would also be a tool that crawls through a python 
  package
  and also checks any missing imports and reports all of them at once. When I
  refactor code, I often have to restart zope3 over and over, only due to
  missing import statements.

I have a quick-and-dirty python script that does exactly this.  It
cannot handle the new Zope import style which is

  import somepackage.somesubpackage
  from somepackage import otherpackage
  import somepackage.otherpackage.othersubpackage

  x = somepackage.somepackage.somevar
  y = otherpackage.othersubpackage.othervar

and which I don't personally use.  (If I wanted verbosity, I know where to
find Java).

(And while I'm on the topic of strong opinions:

A: No.
Q: Should I include quotations after my reply?

)

 Z3 has an importchecker:
 
 Import checker
 
 This utility finds unused imports in Python modules.  Its output is
 grep-like and thus emacs-friendly.
 ...

I ought to try this one out some day...  

 Althought pyflakes works for me better.
 http://www.divmod.org/projects/pyflakes

pyflakes doesn't handle imports that are used by doctests only, e.g.:

  import doctest
  import something

  def doctest_foo():
  
   use something
  

  def doctest_bar():
  
   use something
  

  def test_suite():
  return doctest.DocTestSuite()

Can the import checker in Z3 handle this?

Marius Gedminas
-- 
To stay awake all night adds a day to your life.
-- Stilgar (Frank Herbert _Children_of_Dune_)


signature.asc
Description: Digital signature
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Utility for removing unneeded import statements

2007-06-05 Thread Marius Gedminas
On Tue, Jun 05, 2007 at 06:10:36PM +0200, Adam Groszer wrote:
 Hello Marius,
 
 Tuesday, June 5, 2007, 6:03:52 PM, you wrote:
 
 
  pyflakes doesn't handle imports that are used by doctests only, e.g.:
 ...
  Can the import checker in Z3 handle this?
 
 I don't think so. As I remember it did not find all unnecessary
 imports, that's why I switched to pyflakes.

By pyflakes doesn't handle I meant it found too many unnecessary
imports, some of which were actually very necessary (for the doctests).  

Marius Gedminas
-- 
Linux is not user-friendly.
It _is_ user-friendly.  It is not ignorant-friendly and idiot-friendly.
(Seen somewhere on the net.)


signature.asc
Description: Digital signature
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users