After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 523821 - false errors with pylint
false errors with pylint
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: gobject
2.14.x
Other All
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2008-03-22 10:59 UTC by Simon Schampijer
Modified: 2008-04-15 18:23 UTC
See Also:
GNOME target: ---
GNOME version: 2.19/2.20


Attachments
setting __module__ properly for gobject.GObject (9.00 KB, patch)
2008-03-22 12:45 UTC, Johan (not receiving bugmail) Dahlin
none Details | Review

Description Simon Schampijer 2008-03-22 10:59:24 UTC
Please describe the problem:
I get false errors when using pylint [http://www.logilab.org/857] on code that uses pygobject. 



Steps to reproduce:
1. 
class LiveVideoSlot(gobject.GObject):
    __gsignals__ = {
        'pixbuf': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,   ([gobject.TYPE_PYOBJECT])),
    }
    def __init__(self, width, height):
        gobject.GObject.__init__(self)

    def _new_picture_cb(self, playa, pixbuf):
        self.emit('pixbuf', pixbuf) 



Actual results:
- E1101: Instance of 'LiveVideoSlot' has no 'emit' member
same behavior for 'connect', 'disconnect', 'notify', props



Expected results:
No false errors.

Does this happen every time?
Yes.

Other information:
I asked pylint people about this issue and got the following reply:

i think this is due to a known pb with the way astng is built from
living object (which is necessary when object is coming from C code):
if object's __module__ attribute isn't equivalent to the actual (python)
name of the compiled module, it's missing an important part of available
information. E.g. since :

>>> >>> GObject.__module__
'gobject'

while GObject is actually defined in gobject._gobject, and the same
problem occurs much probably on other objects.
Comment 1 Johan (not receiving bugmail) Dahlin 2008-03-22 12:45:42 UTC
Created attachment 107797 [details] [review]
setting __module__ properly for gobject.GObject

Hmm. I'm not sure what's missing.
I'm using pylint 0.13.2 with the patch applied against the test case you mentioned. GObject.__module__ is set properly to gobject._gobject, but it is still not detecting that emit is a method which exists in the base class.
Any other ideas of what could be wrong/missing?
Comment 2 Simon Schampijer 2008-03-22 13:52:04 UTC
Thanks very much for your quick reply and patch.

I tested your patch against the latest svn and can confirm that GObject.__module__ is set properly to gobject._gobject but pylint still reports false errors. Let me ask the pylint people what data they rely on other than the __module__ one.
Comment 3 Marco Pesenti Gritti 2008-04-15 17:22:02 UTC
Johan, which part of your patch is actually relevant? There are gio bits which I obviously stripped out. The changes in __init__.py causes a backtrace:

  • File "/home/marco/od/install/lib64/python2.5/site-packages/gtk-2.0/gobject/__init__.py", line 69 in <module>
    _PyGObject_API = _gobject._PyGObject_API

Though if I apply only the following bit, stuff seem to work for me:

Index: gobject/gobjectmodule.c
===================================================================
--- gobject/gobjectmodule.c     (revision 776)
+++ gobject/gobjectmodule.c     (working copy)
@@ -3611,6 +3611,9 @@
         return;
     descr = PyObject_New(PyObject, &PyGPropsDescr_Type);
     PyDict_SetItemString(PyGObject_Type.tp_dict, "props", descr);
+    PyDict_SetItemString(PyGObject_Type.tp_dict, "__module__",
+                        o=PyString_FromString("gobject._gobject"));
+    Py_DECREF(o);
 
     REGISTER_GTYPE(d, PyGInterface_Type, "GInterface", G_TYPE_INTERFACE);
     PyDict_SetItemString(PyGInterface_Type.tp_dict, "__doc__",
Comment 4 Simon Schampijer 2008-04-15 18:03:01 UTC
Verified and marco's minimized patch works. 

Btw: I retested Johan's patch yesterday and it was fine as well. I just had to install the patched pygobject instead of running it in the built directory.

Comment 5 Johan (not receiving bugmail) Dahlin 2008-04-15 18:13:33 UTC
Confirmed; It appears both Simon and I tested directly in the root of the pygobject checkout, where it does not work for some reason.

2008-04-15  Johan Dahlin  <johan@gnome.org>

	* gobject/gobjectmodule.c (init_gobject): Set 
	gobject.GObject.__module__ to gobject._gobject, this
	helps pylint to check public methods of GObject subclasses

	* tests/Makefile.am (tests): 
	* tests/test_gobject.py (TestGObjectAPI.testGObjectModule): 
	Add a test for this

	(#523821, Simon Schampijer)
Comment 6 Simon Schampijer 2008-04-15 18:23:49 UTC
Thanks Johan for your great help!