[PyObjC-svn] r2339 - in trunk/pyobjc/pyobjc-core: . Lib/objc PyObjCTest
[email protected] Tue, 13 Oct 2009 06:13:16 -0500
| Newsgroups | gmane.comp.python.pyobjc.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: ronaldoussoren
Date: Tue Oct 13 06:13:16 2009
New Revision: 2339
Log:
Ensure that it is possible to specify both
objectForKey: and __getitem__ in a class (and
simularly for other convenience methods). Without this
patch PyObjC would replace a custom __getitem__ with
a generic one.
Modified:
trunk/pyobjc/pyobjc-core/Lib/objc/_convenience.py
trunk/pyobjc/pyobjc-core/NEWS.txt
trunk/pyobjc/pyobjc-core/PyObjCTest/test_regr.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 06:13:16 2009
@@ -97,7 +97,7 @@
signature=t.signature, isClassMethod=t.isClassMethod)
type_dict[nm] = v
- else:
+ elif nm not in type_dict:
type_dict[nm] = value
if name in CLASS_METHODS:
Modified: trunk/pyobjc/pyobjc-core/NEWS.txt
==============================================================================
--- trunk/pyobjc/pyobjc-core/NEWS.txt (original)
+++ trunk/pyobjc/pyobjc-core/NEWS.txt Tue Oct 13 06:13:16 2009
@@ -7,6 +7,19 @@
Version 2.2 (...)
-----------------
+- BUGFIX: It is now possible to explicitly define ``__getitem__`` (and other
+ special methods) if your class implements ``objectForKey:``::
+
+ class MyObject (NSObject):
+ def objectForKey_(self, k):
+ pass
+
+ def __getitem__(self, k):
+ pass
+
+ In previous version of PyObjC the implementation of ``__getitem__`` would
+ silently be replaced by a generic one.
+
- The default value for the ``__useKVO__`` attribute in class definitions
can now be controlled by ``objc.setUseKVOForSetattr(b)``. The default
is ``True``.
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 06:13:16 2009
@@ -8,6 +8,13 @@
rct = structargs.StructArgClass.someRect.__metadata__()['retval']['type']
+class OCTestRegrWithGetItem (NSObject):
+ def objectForKey_(self, k):
+ return "ofk: %s"%(k,)
+
+ def __getitem__(self, k):
+ return "gi: %s"%(k,)
+
class ReturnAStruct (NSObject):
def someRectWithRect_(self, ((x, y), (h, w))):
return ((x,y),(h,w))
@@ -230,6 +237,12 @@
self.failIf(v is not None)
+ def testExplicitGetItem(self):
+ v = OCTestRegrWithGetItem.alloc().init()
+
+ self.failUnlessEqual(v.objectForKey_("foo"), "ofk: foo")
+ self.failUnlessEqual(v["foo"], "gi: foo")
+
if __name__ == '__main__':
main()
------------------------------------------------------------------------------
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