[PyObjC-svn] r2340 - in trunk/pyobjc/pyobjc-core: Lib/objc PyObjCTest

[email protected] Tue, 13 Oct 2009 07:01:29 -0500
Newsgroups gmane.comp.python.pyobjc.cvs
Message-ID <[email protected]>
Author: ronaldoussoren
Date: Tue Oct 13 07:01:28 2009
New Revision: 2340

Log:
Ensure that __getitem__ in a superclass doesn't
get overwritten by objc._convenience


Modified:
   trunk/pyobjc/pyobjc-core/Lib/objc/_convenience.py
   trunk/pyobjc/pyobjc-core/PyObjCTest/test_regr.py
   trunk/pyobjc/pyobjc-core/PyObjCTest/test_splitsig.py

Modified: trunk/pyobjc/pyobjc-core/Lib/objc/_convenience.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/objc/_convenience.py	(original)
+++ trunk/pyobjc/pyobjc-core/Lib/objc/_convenience.py	Tue Oct 13 07:01:28 2009
@@ -75,6 +75,8 @@
                 "__bundle_hack__ is not necessary in PyObjC 1.3+ / py2app 0.1.8+",
                 DeprecationWarning)
 
+    look_at_super = (super_class is not None and super_class.__name__ != 'Object')
+
     for k, sel in type_dict.items():
         if not isinstance(sel, selector):
             continue
@@ -85,6 +87,7 @@
 
         sel = sel.selector
 
+
         if sel in CONVENIENCE_METHODS:
             v = CONVENIENCE_METHODS[sel]
             for nm, value in v:
@@ -97,6 +100,11 @@
                         signature=t.signature, isClassMethod=t.isClassMethod)
 
                     type_dict[nm] = v
+
+                elif look_at_super and hasattr(super_class, nm):
+                    # Skip, inherit the implementation from a super_class
+                    pass
+
                 elif nm not in type_dict:
                     type_dict[nm] = value
 

Modified: trunk/pyobjc/pyobjc-core/PyObjCTest/test_regr.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/PyObjCTest/test_regr.py	(original)
+++ trunk/pyobjc/pyobjc-core/PyObjCTest/test_regr.py	Tue Oct 13 07:01:28 2009
@@ -15,6 +15,10 @@
     def __getitem__(self, k):
         return "gi: %s"%(k,)
 
+class OCTestRegrWithGetItem2 (OCTestRegrWithGetItem):
+    def objectForKey_(self, k):
+        return "ofk2: %s"%(k,)
+
 class ReturnAStruct (NSObject):
     def someRectWithRect_(self, ((x, y), (h, w))):
         return ((x,y),(h,w))
@@ -243,6 +247,10 @@
         self.failUnlessEqual(v.objectForKey_("foo"), "ofk: foo")
         self.failUnlessEqual(v["foo"], "gi: foo")
 
+        v = OCTestRegrWithGetItem2.alloc().init()
+        self.failUnlessEqual(v.objectForKey_("foo"), "ofk2: foo")
+        self.failUnlessEqual(v["foo"], "gi: foo")
+
 
 if __name__ == '__main__':
     main()

Modified: trunk/pyobjc/pyobjc-core/PyObjCTest/test_splitsig.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/PyObjCTest/test_splitsig.py	(original)
+++ trunk/pyobjc/pyobjc-core/PyObjCTest/test_splitsig.py	Tue Oct 13 07:01:28 2009
@@ -85,6 +85,7 @@
 
             # dictionary methods
             'get',
+            "has_key",
         ]
 
         for cls in objc.getClassList():

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference