Bob Ippolito avatar Bob Ippolito committed ab044f0

slight change to kvo convenience extender

Comments (0)

Files changed (1)


-from _objc import setClassExtender, selector, lookUpClass, currentBundle, repythonify, splitSignature
+from _objc import setClassExtender, selector, lookUpClass, currentBundle, repythonify, splitSignature, ivar
 from itertools import imap
 NSObject = lookUpClass('NSObject')
+HAS_KVO = NSObject.instancesRespondToSelector_('willChangeValueForKey:')
+# This is a crappy way to test, but we need to check.
+# Panther's implementation sends multiple observations for the following:
+#  [self willChangeValueForKey:key];
+#  [self willChangeValueForKey:key];
+#  [self didChangeValueForKey:key];
+#  [self didChangeValueForKey:key];
+HAS_PANTHER_KVO = not NSObject.instancesRespondToSelector_('willChangeValueForKey:withSetMutation:usingObjects:')
 def add_convenience_methods(super_class, name, type_dict):
         return _add_convenience_methods(super_class, name, type_dict)
             def bundleForClass(cls):
                 return cb
             type_dict['bundleForClass'] = selector(bundleForClass, isClassMethod=True)
-            if '__useKVO__' not in type_dict:
+            if HAS_KVO and '__useKVO__' not in type_dict:
                 if not (
                         'willChangeValueForKey_' in type_dict
                         or 'didChangeValueForKey_' in type_dict):
-                    type_dict['__useKVO__'] = issubclass(super_class, NSObject)
+                    useKVO = issubclass(super_class, NSObject)
+                    type_dict['__useKVO__'] = useKVO
+                    if useKVO and HAS_PANTHER_KVO:
+                        type_dict['__pyobjc_kvo_stack__'] = ivar('__pyobjc_kvo_stack__')
         if '__bundle_hack__' in type_dict:
             import warnings
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.