Commit bf84915f authored by Johan Dahlin's avatar Johan Dahlin Committed by Simon Feltman

Add GTypeClass methods as Python GObject class methods

Take all the methods from an objects type classs and add them
as class methods. For instance, GObject.ObjectClass.list_properties
is available as GObject.Object.list_properties().
Co-Authored-By: default avatarSimon Feltman <>
parent 778d05c9
......@@ -55,6 +55,17 @@ class MetaClassHelper(object):
for method_info in cls.__info__.get_methods():
setattr(cls, method_info.__name__, method_info)
def _setup_class_methods(cls):
info = cls.__info__
class_struct = info.get_class_struct()
if class_struct is None:
for method_info in class_struct.get_methods():
name = method_info.__name__
# Don't mask regular methods or base class methods with TypeClass methods.
if not hasattr(cls, name):
setattr(cls, name, classmethod(method_info))
def _setup_fields(cls):
for field_info in cls.__info__.get_fields():
name = field_info.get_name().replace('-', '_')
......@@ -211,6 +222,8 @@ class GObjectMeta(_GObjectMetaBase, MetaClassHelper):
if is_python_defined:
elif is_gi_defined:
if isinstance(cls.__info__, ObjectInfo):
......@@ -63,5 +63,18 @@ class TestCoercion(unittest.TestCase):
GObject.ObjectClass.find_property(42, 'some-int')
class TestTypeClassMethodsMovedToClass(unittest.TestCase):
def test_list_child_properties(self):
pspecs = GIMarshallingTests.PropertiesObject.list_properties()
pnames = [ for pspec in pspecs]
self.assertTrue('some-int' in pnames)
self.assertTrue('some-float' in pnames)
self.assertTrue('some-char' in pnames)
def test_find_child_property(self):
pspec = GIMarshallingTests.PropertiesObject.find_property('some-int')
self.assertEqual(, 'some-int')
if __name__ == '__main__':
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment