[Python-projects] Problem and Fix for PyQt4 and pylint
Sylvain Thénault
sylvain.thenault at logilab.fr
Tue Jul 28 14:37:21 CEST 2009
On 27 juillet 18:53, Derek Harland wrote:
> Hello,
Hi,
> 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
even if having a fix for this on the pylint/astng side, this is probably
worth mentionning to the pyqt team.
> 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
which error ? False positives as mentioned above ?
> --- 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)
could you provide which version of pyqt are you using and a minimal
sample script to reproduce the pb ?
imo (but I've not at all tracked down this as you have), a better fix
consits in giving to object_build_* methods the name of the member
(eg the loop variable) if member.__name__ is not set.
> 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).
Weird
> Hope this is useful, I know that there are a few posts to newsgroups
> wondering how to fix this problem
Bug reports, moreover those including results of digging the code, are
really valuable! Thank you for this one.
--
Sylvain Thénault LOGILAB, Paris (France)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure: http://www.logilab.fr/services
CubicWeb, the semantic web framework: http://www.cubicweb.org
More information about the Python-Projects
mailing list