Add better REPL descriptions for Objective-C objects
@@ -31,6 +31,8 @@ if "widget" not in os.environ:
from types import ModuleType as Module
import stopit
import asyncio
+ from rubicon.objc import ObjCInstance
+ from Foundation import NSObject
try:
from rubicon.objc import *
@@ -86,10 +88,19 @@ def displayhook(_value):
return val
+ _repr = repr(_value)
+
if isinstance(_value, tuple):
_value = list(_value)
- if isinstance(_value, Mapping) or isinstance(_value, list) or hasattr(_value, "__dict__"):
+ if isinstance(_value, ObjCInstance): # We assume it's an instance or subclass of NSObject
+ _repr = str(_value.debugDescription)
+ val = {
+ "Description": _repr,
+ "Superclass": str(_value.superclass.name),
+ "Methods": str(_value._methodDescription())
+ }
+ elif isinstance(_value, Mapping) or isinstance(_value, list) or hasattr(_value, "__dict__"):
val = represent(_value)
else:
val = represent([_value])
