GNOME Bugzilla – Bug 523821
false errors with pylint
Last modified: 2008-04-15 18:23:49 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.
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?
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.
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:
+ Trace 195304
_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__",
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.
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)
Thanks Johan for your great help!