diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2014-04-08 12:11:14 +0200 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2014-04-08 12:11:14 +0200 |
commit | b004dba14b183a74d71800c9a582f4961aa0bbf1 (patch) | |
tree | 796d60354d0d3258352f185404605549a0a6f520 | |
parent | b2eb1594309b1600e3e7f1e41c6730af4374e54a (diff) | |
download | astroid-b004dba14b183a74d71800c9a582f4961aa0bbf1.tar.gz |
backport gi related changes from pylint-brain, closes #19 and #22
-rw-r--r-- | brain/py2gi.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/brain/py2gi.py b/brain/py2gi.py index 5001b7c..dd9868d 100644 --- a/brain/py2gi.py +++ b/brain/py2gi.py @@ -5,6 +5,7 @@ Helps with understanding everything imported from 'gi.repository' import inspect import sys +import re from astroid import MANAGER, AstroidBuildingException from astroid.builder import AstroidBuilder @@ -12,6 +13,7 @@ from astroid.builder import AstroidBuilder _inspected_modules = {} +_identifier_re = r'^[A-Za-z_]\w*$' def _gi_build_stub(parent): """ @@ -23,9 +25,13 @@ def _gi_build_stub(parent): constants = {} methods = {} for name in dir(parent): - if not name or name.startswith("__"): - # GLib.IConv has a parameter named "" :/ + 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: @@ -46,6 +52,12 @@ def _gi_build_stub(parent): str(obj).startswith("<GType ") or inspect.isdatadescriptor(obj)): constants[name] = 0 + elif callable(obj): + # Fall back to a function for anything callable + functions[name] = obj + else: + # Assume everything else is some manner of constant + constants[name] = 0 ret = "" |