Commits

Lucian Brănescu-Mihăilă committed 6b693d0

Reverted to 116 for type.winxed and object.winxed. Many more object system tests pass.

Comments (0)

Files changed (3)

objects/src/instance.winxed

         if(exists dict['__class__']) {
             var cls = dict['__class__'];
 
+            say('looking for __setattr__');
+
             for(var i in get_mro(cls)) {
-                if(exists i.__dict__['__setattr__'])
+                if(exists i.__dict__['__setattr__']) {
+                    say('calling __setattr__');
+
                     i.__dict__['__setattr__'](self, name, value);
-
-                return;
+                    return;
+                }
             }
         }
 

objects/src/object.winxed

     t.__call__ = function() {
         var n = t.__new__(t);
         //n.__init__(n);
-
         return n;
     };
 
         return string(sb);
     };
 
-    t.__getattribute__ = function(obj, key) {
-        var cls = obj.__dict__['__class__'];
-        var chain = get_mro(cls);
-       
-        say('trying data descriptors');
-        // first try descriptor among class attrs
-        for(var i in chain) {
-            if(exists i.__dict__[key]) {
-                var attr = i.__dict__[key];
-
-                // only for python objects
-                if(typeof(attr) == 'Python;instance') {
-
-                    if(exists attr.__dict__['__class__']) {
-                        var attr_cls = i.__dict__['__class__'];
-                        
-                        // if data-descriptor
-                        if(exists attr_cls.__dict__['__get__'] && exists attr_cls.__dict__['__set__']) {
-                            return attr_cls.__dict__['__get__'](cls, obj);
-                        }
-                    }
-                }
-            }
-        }
-
-        //say(cls.__dict__['__name__']);
-        
-        say('trying on actual obj');
-        // then attr on actual obj
-        if(id(cls) == id(type)) { // if is class
-            say('class');
-            for(var i in get_mro(obj)) {
-                if(exists i.__dict__[key]) { // if has attr
-                    var attr = i.__dict__[key];
-                
-                    // only for python objects
-                    if(typeof(attr) == 'Python;instance') {
-                        if(exists attr.__dict__['__class__']) { // if attr has class
-                            var attr_cls = attr.__dict__['__class__'];
-
-                            if(exists attr_cls.__dict__['__get__']) { // if attr is descriptor
-                                say('using data descriptor');
-                                return i.__dict__['__get__'](i, obj);
-                            } else {
-                                return attr;
-                            }
-                        }
-                    }
-                }
-            }
-        } else if(exists obj.__dict__[key]) {
-            say('not class');
-            return obj.__dict__[key];
-        }
-
-        say('data descriptors on class');
-        // then on the obj's class
-        for(var i in chain) {
-            if(exists i.__dict__[key]) {
-                var attr = i.__dict__[key];
-            
-                // only for python objects
-                if(typeof(attr) == 'Python;instance') {
-                
-                    // if descriptor
-                    if(exists attr.__dict__['__get__'])
-                        return attr.__dict__['__get__'](i, obj);
-                }
-
-                return attr;
-            }
-        }
-
-        throw 'AttributeError';
-    };
-
-    t.__setattr__ = function(obj, key, val) {
-        var cls = obj.__dict__['__class__'];
-        
-        if(exists cls.__dict__[key]) {
-            var attr = cls.__dict__[key];
-
-            // only for python objects
-            if(typeof(attr) == 'Python;instance') {
-                if(exists attr.__dict__['__set__']) {
-                    say('using data descriptor');
-                    attr.__dict__['__set__'](attr, obj, val);
-                    return;
-                }
-            }
-        }
-        
-        say('setting on __dict__');
-        obj.__dict__[key] = val;
-    };
-
     return t;
 }
 

objects/src/type.winxed

  
     t.__str__ = t.__repr__;
 
+    t.__getattribute__ = function(obj, key) {
+        var cls = obj.__dict__['__class__'];
+        
+        // first try descriptor among class attrs
+        if(exists cls.__dict__[key]) {
+            var attr = cls.__dict__[key];
+   
+            // only for python objects
+            if(typeof(attr) == 'Python;instance')
+                // if data-descriptor
+                if(exists attr.__dict__['__get__'] && exists attr.__dict__['__set__'])
+                    return attr.__dict__['__get__'](attr, obj);
+        }
+        
+        var chain = get_mro(cls);
+
+        // then attr on actual obj
+        if(exists obj.__dict__[key]) {
+            var attr = obj.__dict__[key];
+
+            // if obj is a class
+            if(id(cls) == id(t))
+                for(var i in chain)
+                    if(exists i.__dict__['__get__'])
+                        attr = i.__dict__['__get__'](i, obj);
+
+            return attr;
+        }
+
+        // then on the obj's class
+        for(var i in chain) {
+            if(exists i.__dict__[key]) {
+                var attr = i.__dict__[key];
+            
+                // only for python objects
+                if(typeof(attr) == 'Python;instance') {
+                
+                    // if data-descriptor
+                    if(exists attr.__dict__['__get__'] && exists attr.__dict__['__set__'])
+                        return attr.__dict__['__get__'](attr, obj);
+                    // if non-data descriptor
+                    if(exists attr.__dict__['__get__'])
+                        return attr.__dict__['__get__'](attr, obj);
+                }
+
+                return attr;
+            }
+        }
+
+        // throw AttributeError
+    };
+
+    t.__setattr__ = function(obj, key, val) {
+        var cls = obj.__dict__['__class__'];
+        
+        /* disable data descriptors for now
+        if(exists cls.__dict__[key]) {
+            var attr = cls.__dict__[key];
+
+            if(exists attr.__dict__['__set__']) {
+                say('using data descriptor');
+                attr.__dict__['__set__'](attr, obj, val);
+                return;
+            }
+        }
+        */
+
+        obj.__dict__[key] = val;
+    };
+
     return t;
 }