Skip to content

Commit

Permalink
Refactor a bit to make sure that it is possible to use in subclasses,
Browse files Browse the repository at this point in the history
2007-08-27  Johan Dahlin  <jdahlin@async.com.br>

    * gobject/__init__.py (GObjectMeta._install_properties): 
    Refactor a bit to make sure that it is possible to use in subclasses,
    fixes #470718 (Marco Giusti)


svn path=/trunk/; revision=699
  • Loading branch information
Johan Dahlin authored and Johan Dahlin committed Aug 27, 2007
1 parent 078439f commit f66505b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2007-08-27 Johan Dahlin <jdahlin@async.com.br>

* gobject/__init__.py (GObjectMeta._install_properties):
Refactor a bit to make sure that it is possible to use in subclasses,
fixes #470718 (Marco Giusti)

2007-08-27 Marco Giusti <marco.giusti@gmail.com>

reviewed by: Gustavo J. A. M. Carneiro
Expand Down
15 changes: 7 additions & 8 deletions gobject/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,26 @@ def __init__(cls, name, bases, dict_):

def _install_properties(cls):
gproperties = getattr(cls, '__gproperties__', {})
props = {}

props = []
for name, prop in cls.__dict__.items():
if isinstance(prop, property): # not same as the built-in
if name in gproperties:
raise ValueError
prop.name = name
props[name] = prop.get_pspec_args()
gproperties[name] = prop.get_pspec_args()
props.append(prop)

if not props:
return

if not gproperties:
cls.__gproperties__ = props
else:
gproperties.update(props)
cls.__gproperties__ = gproperties

if (hasattr(cls, 'do_get_property') or
hasattr(cls, 'do_set_property')):
for prop in props:
if (prop.getter != prop.default_getter or
prop.setter != prop.default_setter):
if (prop.getter != prop._default_getter or
prop.setter != prop._default_setter):
raise TypeError(
"GObject subclass %r defines do_get/set_property"
" and it also uses a property which a custom setter"
Expand Down
14 changes: 14 additions & 0 deletions tests/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,20 @@ class PropertyObject(GObject):
pobj1 = pobj2.obj
self.assertEqual(hash(pobj1), obj1_hash)

def testPropertySubclass(self):
# test for #470718
class A(GObject):
prop1 = gobject.property(type=int)

class B(A):
prop2 = gobject.property(type=int)

b = B()
b.prop2 = 10
self.assertEquals(b.prop2, 10)
b.prop1 = 20
self.assertEquals(b.prop1, 20)


if __name__ == '__main__':
unittest.main()

0 comments on commit f66505b

Please sign in to comment.