[pygobject] Change install_properties to not use getattr on classes



commit 31061f20083aa60919f6763a12addbf2b052cab7
Author: Simon Feltman <sfeltman src gnome org>
Date:   Sun Oct 21 18:55:24 2012 -0700

    Change install_properties to not use getattr on classes
    
    The usage of getattr for accessing a classes __gproperties__
    variable can be problematic due to the potential of it returning
    the parent classes variable when it does not exist on the sub-class.
    Similar to the fix for https://bugzilla.gnome.org/show_bug.cgi?id=686496,
    cls.__dict__.get is used to ensure this does not happen.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=686559

 gi/_gobject/propertyhelper.py |    2 +-
 tests/test_properties.py      |    6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/gi/_gobject/propertyhelper.py b/gi/_gobject/propertyhelper.py
index a1e82c0..d6deb6d 100644
--- a/gi/_gobject/propertyhelper.py
+++ b/gi/_gobject/propertyhelper.py
@@ -350,7 +350,7 @@ def install_properties(cls):
     Scans the given class for instances of Property and merges them
     into the classes __gproperties__ dict if it exists or adds it if not.
     """
-    gproperties = getattr(cls, '__gproperties__', {})
+    gproperties = cls.__dict__.get('__gproperties__', {})
 
     props = []
     for name, prop in cls.__dict__.items():
diff --git a/tests/test_properties.py b/tests/test_properties.py
index 230ccd3..490b1ae 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -753,7 +753,9 @@ class TestInstallProperties(unittest.TestCase):
         test = GObject.Property(type=int)
 
     def setUp(self):
+        self.assertEqual(len(self.Base.__gproperties__), 1)
         propertyhelper.install_properties(self.Base)
+        self.assertEqual(len(self.Base.__gproperties__), 1)
 
     def test_subclass_without_properties_is_not_modified(self):
         self.assertFalse('__gproperties__' in self.Sub1.__dict__)
@@ -769,8 +771,8 @@ class TestInstallProperties(unittest.TestCase):
 
         propertyhelper.install_properties(self.Sub2)
         self.assertTrue('__gproperties__' in self.Sub2.__dict__)
-        self.assertEqual(len(self.Base.__gproperties__), 2)
-        self.assertEqual(len(self.Sub2.__gproperties__), 2)
+        self.assertEqual(len(self.Base.__gproperties__), 1)
+        self.assertEqual(len(self.Sub2.__gproperties__), 1)
         self.assertTrue('sub2test' in self.Sub2.__gproperties__)
 
         # get/set vfuncs should have been added



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]