summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2014-09-13 07:56:42 -0400
committerCole Robinson <crobinso@redhat.com>2014-09-13 07:56:42 -0400
commita761ee3debb75e6e16e27843b1c6879f119ba316 (patch)
treeb272a0533fe4c938598345b717d1237404a7c950
parentc429af742654324efb254a99ebaa21b05c9fbb64 (diff)
downloadastroid-fix-pygi-glib3.tar.gz
brain: gi: fix glib detectionfix-pygi-glib3
pygobject has some special hidden modules that we need to inspect for glib and gobject. However, on latest pygobject, the hidden glib module has been removed, which caused pylint to fail to detect glib whatsoever. Tread errors in processing these hidden modules as non-fatal. Closes astroid issue #49
-rw-r--r--brain/py2gi.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/brain/py2gi.py b/brain/py2gi.py
index dd9868d..20356c1 100644
--- a/brain/py2gi.py
+++ b/brain/py2gi.py
@@ -4,6 +4,7 @@ Helps with understanding everything imported from 'gi.repository'
"""
import inspect
+import itertools
import sys
import re
@@ -134,17 +135,26 @@ def _new_import_module(self, modname, relative_only=False, level=None):
# build astroid representation unless we already tried so
if modname not in _inspected_modules:
modnames = [modname]
- # GLib and GObject have some special case handling
- # in pygobject that we need to cope with
+ optional_modnames = []
+
+ # GLib and GObject may have some special case handling
+ # in pygobject that we need to cope with. However at
+ # least as of pygobject3-3.13.91 the _glib module doesn't
+ # exist anymore, so if treat these modules as optional.
if modname == 'gi.repository.GLib':
- modnames.append('gi._glib')
+ optional_modnames.append('gi._glib')
elif modname == 'gi.repository.GObject':
- modnames.append('gi._gobject')
+ optional_modnames.append('gi._gobject')
+
try:
modcode = ''
- for m in modnames:
- __import__(m)
- modcode += _gi_build_stub(sys.modules[m])
+ for m in itertools.chain(modnames, optional_modnames):
+ try:
+ __import__(m)
+ modcode += _gi_build_stub(sys.modules[m])
+ except ImportError:
+ if m not in optional_modnames:
+ raise
except ImportError:
astng = _inspected_modules[modname] = None
else: