"""Astroid hooks for the Python 2 GObject introspection bindings. Helps with understanding everything imported from 'gi.repository' """ import inspect import itertools import sys import re from astroid import MANAGER, AstroidBuildingException from astroid.builder import AstroidBuilder _inspected_modules = {} _identifier_re = r'^[A-Za-z_]\w*$' def _gi_build_stub(parent): """ Inspect the passed module recursively and build stubs for functions, classes, etc. """ classes = {} functions = {} constants = {} methods = {} for name in dir(parent): if name.startswith("__"): continue # Check if this is a valid name in python if not re.match(_identifier_re, name): continue try: obj = getattr(parent, name) except: continue if inspect.isclass(obj): classes[name] = obj elif (inspect.isfunction(obj) or inspect.isbuiltin(obj)): functions[name] = obj elif (inspect.ismethod(obj) or inspect.ismethoddescriptor(obj)): methods[name] = obj elif type(obj) in [int, str]: constants[name] = obj elif (str(obj).startswith("