Commits

Lucian Brănescu-Mihăilă  committed c554982

Fix __getattribute__. Disable data descriptors on __setattr__ for now. Many more type.t tets pass.

  • Participants
  • Parent commits 3998271

Comments (0)

Files changed (4)

File objects/src/instance.winxed

         // let object classes override it
         if(exists dict['__class__']) {
             var cls = dict['__class__'];
-            var chain = get_mro(cls);
 
-            for(var i in chain) {
+            for(var i in get_mro(cls)) {
                 if(exists i.__dict__['__getattribute__'])
                     return i.__dict__['__getattribute__'](self, name);
             }
         if(exists dict['__class__']) {
             var cls = dict['__class__'];
 
-            if(exists cls.__dict__['__setattr__'])
-                cls.__dict__['__setattr__'](self, name, value);
+            for(var i in get_mro(cls)) {
+                if(exists i.__dict__['__setattr__']) {
+                    i.__dict__['__setattr__'](self, name, value);
 
-            return;
+                    return;
+                }
+            }
         }
 
         dict[name] = value;

File objects/src/object.winxed

 function object(type) {
     var t = new Python.instance;
     
-    //say('created object');
     t.__class__ = type;
-    //say('set class');
     t.__bases__ = [];
-    //say('set bases');
 
     t.__name__ = 'object';
     t.__module__ = 'builtins';
 
     t.__init__ = function(obj) {};
 
-    t.__call__ = function(cls) {
-        var f = cls.__new__;
-        var n = f(cls);
-        f = n.__init__;
-        f(n);
+    t.__call__ = function() {
+        var f = t.__new__;
+        var n = f(t);
+        //f = n.__init__;
+        //f(n);
+        n.__init__(n);
         return n;
     };
 

File objects/src/type.winxed

     t.__str__ = t.__repr__;
 
     t.__getattribute__ = function(obj, key) {
-        say(typeof(obj));
         var cls = obj.__dict__['__class__'];
         
         // first try descriptor among class attrs
         if(exists cls.__dict__[key]) {
             var attr = cls.__dict__[key];
-    
-             // if data-descriptor
-             if(exists attr.__dict__['__get__'] &&
-                exists attr.__dict__['__set__']) {
-                 return attr.__dict__['__get__'](attr, obj);
-             }
+   
+            // 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);
             var attr = obj.__dict__[key];
 
             // if obj is a class
-            if(id(cls) == id(t)) {
-                 
-                for(var i in chain) {
+            if(id(cls) == id(t))
+                for(var i in chain)
                     if(exists i.__dict__['__get__'])
                         attr = i.__dict__['__get__'](i, obj);
-                }
-            }
 
             return attr;
         }
             if(exists i.__dict__[key]) {
                 var attr = i.__dict__[key];
             
-                // if non-data descriptor
-                if(exists attr.__dict__['__get__'])
-                    return attr.__dict__['__get__'](attr, obj);
+                // 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;
             }
     };
 
     t.__setattr__ = function(obj, key, val) {
-        say('calling setattr override');
         var cls = obj.__dict__['__class__'];
-    
+        
+        /* disable data descriptors for now
         if(exists cls.__dict__[key]) {
-            say('using data descriptor');
             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;
     };

File objects/t/type.t

     function bases() {
         :(var t, var o) = boot();
 
-        for(var i in o.__dict__) {say(i);};
-
-        self.assert.equal(o.__dict__['__bases__'], [t]);
+        self.assert.equal(o.__dict__['__bases__'], []);
+        self.assert.equal(t.__dict__['__bases__'], [o]);
     }
 
     function set_attr() {
         :(var t, var o) = boot();
 	
         o.a = 42;
-        say(o.__dict__['__name__']);
         self.assert.equal(o.__dict__['a'], 42);
     }
 
     }
 
     function object_repr() {
-        self.status.todo('__getattribute__ is broken');
         :(var t, var o) = boot();
         
         self.assert.equal(string(o), "<class 'object'>");
         self.assert.same(o.__hash__, t.__dict__['__hash__']);
     }
 
-    function instance_init() {
+    function object_new() {
+        :(var t, var o) = boot();
+        
+        var i = o.__new__(o);
+
+        self.assert.same(i.__class__, o);
+    }
+
+    function instance_create() {
         :(var t, var o) = boot();
 
-        var func = o.__new__;
-        var i = func(o);
-        self.assert.throws_nothing(function(){
-            var a = i.__init__;
-        });
+        var i = o();
+        say(i.__class__.__name__);
+        
+        //self.assert.same(i.__class__, o);
     }
         
     function instance_get() {
 
         var func = o.__new__;
         var i = func(o);
+        say(typeof(i));
 
         o.bla = function(obj){return 42;};