[Zope-Coders] Fwd: pychecker & zope3 (Neal Norwitz)

Jeremy Hylton jeremy@alum.mit.edu
Thu, 26 Sep 2002 23:55:59 -0400


--ZwpnPrjFPe
Content-Type: text/plain; charset=us-ascii
Content-Description: message body text
Content-Transfer-Encoding: 7bit

Neal Norwitz has made great strides towards getting pychecker to work
correctly with Zope and Zope3.  The Zope code base was a pretty good
stress test and uncovered a number of pychecker bugs, but it looks
like they are almost all fixed.

Once the last few bugs get worked out, I'd recommend that we make
pychecker a default part of the unit tests.  In Zope3, if you run with
test.py -C then the tests will be run under pychecker.  In addition to
the unittest output, you'll get pychecker warnings.  It often catches
bugs that would go unnoticed for a long time -- usually bugs in
branches seldom taken or except clauses never trigger.

We can make the -C option the default.  That is, I'd recommend
changing test.py to load pychecker if its available.  We'd need an
option to disable it.

Jeremy


--ZwpnPrjFPe
Content-Type: message/rfc822
Content-Description: forwarded message
Content-Transfer-Encoding: 7bit

MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Return-Path: <neal@metaslash.com>
Delivered-To: jhylton@speakeasy.net
Received: (qmail 13699 invoked from network); 27 Sep 2002 03:51:18 -0000
Received: from unknown (HELO mail.python.org) ([12.155.117.29])
          (envelope-sender <neal@metaslash.com>)
          by mail17.speakeasy.net (qmail-ldap-1.03) with SMTP
          for <jhylton@speakeasy.net>; 27 Sep 2002 03:51:18 -0000
Received: from alum.mit.edu ([18.7.21.81])
	by mail.python.org with esmtp (Exim 4.05)
	id 17um9q-0000R4-00
	for jeremy@python.org; Thu, 26 Sep 2002 23:51:14 -0400
Received: from epoch.metaslash.com (bgp01540536bgs.gambrl01.md.comcast.net [68.48.19.70])
	by alum.mit.edu (8.9.2/8.9.3) with ESMTP id XAA06449
	for <jeremy@alum.mit.edu>; Thu, 26 Sep 2002 23:51:13 -0400 (EDT)
Received: from metaslash.com (localhost [127.0.0.1])
	by epoch.metaslash.com (8.11.6/8.11.6) with ESMTP id g8R3nMU16155;
	Thu, 26 Sep 2002 23:49:23 -0400
Sender: neal@epoch.metaslash.com
Message-ID: <3D93D541.3B1255E@metaslash.com>
Organization: MetaSlash, Inc.
X-Mailer: Mozilla 4.78 [en] (X11; U; Linux 2.4.7-10 i686)
X-Accept-Language: en
X-Spam-Status: No, hits=-7.2 required=5.0 tests=BODY_PYTHON_ZOPE,WEIRD_PORT,UNIFIED_PATCH
X-Spam-Level: 
From: Neal Norwitz <neal@metaslash.com>
To: PyChecker <pychecker-list@lists.sourceforge.net>
CC: Jeremy Hylton <jeremy@alum.mit.edu>
Subject: pychecker & zope3
Date: Thu, 26 Sep 2002 23:49:21 -0400

Importing pychecker was very broken.  Code at the module scope was not
used.  That was the reason why there were so many spurious warnings.

I can now run pychecker reasonably well on zope3.  I let it go for
about a minute before I got tired of waiting for more warnings. :-)
But it didn't crash!

The 21 warnings pychecker produced on zope3 are at the bottom 
of this message.  Most of these are spurious.  There's a bug 
which causes all the 'Invalid arguments' warning.  I need 
to fix that.  I also need to add a config option to disable 
the 'Global variable not defined in module scope', since 
it is not an error.  Probably ought to do the same for 
'Statement appears to have no effect' warning too...
(ie, add a config option)

There are 2 'No global found' warnings which both seem correct.
ie, They are bugs in zope3 I believe.

I still need to get line numbers working in Python 2.3 (or on optimized
byte code).  Right now the lines are the first line number of the function.

I have one outstanding change in function.py.  I'm not sure it's required.
That is at the end of this message.  I will probably check this patch in 
after more testing.

If anyone has any feedback or experience with importing pychecker,
that would be great.

Neal
--
lib/python/Interface/Registry/TypeRegistry.py:46: Invalid arguments to (isImplementedBy), got 1, expected 2
lib/python/Interface/tests/unitfixtures.py:14: Invalid arguments to (deferred), got 0, expected 1
lib/python/ZODB/Connection.py:517: No global (POSException) found
lib/python/Persistence/Class.py:234: Global variable (P) not defined in module scope
lib/python/Persistence/Class.py:234: Global variable (PC) not defined in module scope
lib/python/Zope/Configuration/meta.py:141: Invalid arguments to (isImplementedBy), got 1, expected 2
lib/python/Zope/Security/Checker.py:84: Statement appears to have no effect
lib/python/Zope/Security/Checker.py:152: Invalid arguments to (isImplementedBy), got 1, expected 2
lib/python/Zope/App/ContentDirective/tests/TestModuleHookup.py:19: No module attribute (App) found
lib/python/Zope/Schema/IField.py:173: Invalid arguments to (isImplementedBy), got 1, expected 2
lib/python/Zope/App/Forms/Widget.py:75: No global (CustomWidgets) found
lib/python/Zope/App/Forms/Views/Browser/Widget.py:266: Invalid arguments to (renderElement), got 2, expected 1
lib/python/Zope/App/Forms/Views/Browser/Widget.py:270: Invalid arguments to (renderElement), got 2, expected 1
lib/python/Zope/App/Forms/Views/Browser/Widget.py:364: Invalid arguments to (renderElement), got 2, expected 1
lib/python/Zope/App/Forms/Views/Browser/Widget.py:367: Invalid arguments to (renderElement), got 2, expected 1
lib/python/Zope/App/Forms/Views/Browser/FormView.py:49: Invalid arguments to (isImplementedBy), got 1, expected 2
lib/python/Zope/Schema/_Schema.py:20: Invalid arguments to (isImplementedBy), got 1, expected 2
lib/python/Zope/Schema/_Schema.py:46: Invalid arguments to (isImplementedBy), got 1, expected 2
lib/python/Zope/TAL/XMLParser.py:65: Global variable (XMLParseError) not defined in module scope
lib/python/Zope/ZTUtils/Iterator.py:28: Statement appears to have no effect
lib/python/Zope/ZTUtils/Iterator.py:71: Statement appears to have no effect


Patch:

diff -u -r1.15 function.py
--- pychecker/function.py       14 Mar 2002 02:01:12 -0000      1.15
+++ pychecker/function.py       27 Sep 2002 03:44:32 -0000
@@ -70,9 +70,13 @@
         if function.func_defaults is not None :
             self.minArgs = self.minArgs - len(function.func_defaults)
         # if function uses *args, there is no max # args
-        if function.func_code.co_flags & _ARGS_ARGS_FLAG != 0 :
-            self.maxArgs = None
-        self.supportsKW = function.func_code.co_flags & _KW_ARGS_FLAG
+        try:
+            if function.func_code.co_flags & _ARGS_ARGS_FLAG != 0 :
+                self.maxArgs = None
+            self.supportsKW = function.func_code.co_flags & _KW_ARGS_FLAG
+        except AttributeError:
+            # this happens w/Zope
+            self.supportsKW = 0
 
     def __str__(self):
         return self.function.func_name


--ZwpnPrjFPe--