[Python-projects] Problem and Fix for PyQt4 and pylint

Derek Harland derek at chocolate-fish.com
Mon Jul 27 08:53:44 CEST 2009


Hello,

The more recent releases of PyQt4 seem to break pylint ... pylint will  
emit the following errors
(i) unable to find submodules of PyQt4
     main.py:3: [E0611] No name 'QtCore' in module 'PyQt4'
     main.py:4: [E0611] No name 'QtGui' in module 'PyQt4'
(ii) as a result, all use of classes from eg QtGui, or inheritors from  
them, spark lots of errors
     main.py:11: [E1101, MyValidator] Module 'PyQt4.QtGui2' has no  
'QValidator' member
     main.py:33: [E1101, DaycountWidget.__init__] Instance of  
'DaycountWidget' has no 'setEditable' member

I've tracked down the problem I believe ...
* PyQt4.QtCore's namespace has instances of a c-module defined type  
called pyqtSignal
* pylint believes these are methoddescriptors  
[inspect.ismethoddescriptor(.) -> returns true ]
* However, they do not have __name__ or __doc__ defined, which logilab/ 
astng/raw_building.py:object_build_methoddescriptor expects

As a result pylint basically refuses to load the Qt modules and this  
causes all subsequent errors.

How to fix?  The following patch will avoid the error

--- logilab/astng/builder.py.orig	2009-07-27 18:43:54.000000000 +1200
+++ logilab/astng/builder.py	2009-07-27 18:44:57.000000000 +1200
@@ -194,8 +194,12 @@
                      # recursion
                      self.object_build(class_node, member)
              elif ismethoddescriptor(member):
-                assert isinstance(member, object)
-                object_build_methoddescriptor(node, member)
+                # avoid objects without __name__, they're not what  
they seem ...
+                # (eg PyQt4.QtCore.pyqtSignal instances)
+                if hasattr(member, "__name__") and hasattr(member,  
"__doc__"):
+                    assert isinstance(member, object)
+                    object_build_methoddescriptor(node, member)
+                else: attach_dummy_node(node, name, member)
              elif isdatadescriptor(member):
                  assert isinstance(member, object)
                  object_build_datadescriptor(node, member, name)

After this patch pylint seems to work as expected.  However users must  
ensure their code imports PyQt4.QtGui before PyQt4.QtCore or a bus  
error will occur when running pylint. (I have no idea why ... within a  
python program itself it doesn't mind the order in which they are  
imported).

Hope this is useful, I know that there are a few posts to newsgroups  
wondering how to fix this problem
Derek.




More information about the Python-Projects mailing list