Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Final meta patch
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Phil Hassey  
View profile  
 More options Jun 10 2008, 8:49 pm
From: Phil Hassey <philhas...@yahoo.com>
Date: Tue, 10 Jun 2008 17:49:30 -0700 (PDT)
Local: Tues, Jun 10 2008 8:49 pm
Subject: Final meta patch

Hey,

So .. here's another class / meta patch.&nbsp; This one combines the "best of the best" from all the previous approaches.

- In python code, you can write really clean class interfaces (like in the python style patch).
- You also get a getmeta / setmeta function which you can use to change the "class" of an object.&nbsp; Or even change the parent class of a class.&nbsp; Or whatever.
- You can change methods on a class "real-time" and the objects will "reflect" those changes since methods are looked-up at request.
- Memory use is reduced for objects with dozens of methods as these methods aren't all created upon instantiation of an object.
- Speed increase is only 10%, which is quite good.
- Internally dicts can be in any of 3 states: "default" which will check its meta on a get.&nbsp; "object" which will check its metas do various meta actions for you and will return found functions as methods.&nbsp; "raw" which ignores its meta.&nbsp; (There might be some bugs in my differentiation of "object" vs "default" .. these will have to be fixed.)

Feedback requested before I commit this.&nbsp; I'm thinking this one is looking pretty good ...

-Phil

  meta4.patch
20K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Phil Hassey  
View profile  
 More options Jun 10 2008, 10:47 pm
From: Phil Hassey <philhas...@yahoo.com>
Date: Tue, 10 Jun 2008 19:47:12 -0700 (PDT)
Local: Tues, Jun 10 2008 10:47 pm
Subject: Re: [tinypy] Final meta patch

I've patched the hole I alluded to in the previous post ...&nbsp; I think the three "kinds" of dicts are now properly distinct.

Allefant - take a good look at this patch, I think it does everything you want, cleanly and quickly.

-Phil

--- On Tue, 6/10/08, Phil Hassey &lt;philhas...@yahoo.com&gt; wrote:
From: Phil Hassey &lt;philhas...@yahoo.com&gt;
Subject: [tinypy] Final meta patch
To: tinypy@googlegroups.com
Date: Tuesday, June 10, 2008, 6:49 PM

Hey,

So .. here's another class / meta patch.&nbsp; This one combines the "best of the best" from all the previous approaches.

- In python code, you can write really clean class interfaces (like in the python style patch).
- You also get a getmeta / setmeta function which you can use to change the "class" of an object.&nbsp; Or even change the parent class of a class.&nbsp; Or whatever.
- You can change methods on a class "real-time" and the objects will "reflect" those changes since methods are looked-up at request.
- Memory use is reduced for objects with dozens of methods as these methods aren't all created upon instantiation of an object.
- Speed increase is only 10%, which is quite good.
- Internally
 dicts can be in any of 3 states: "default" which will check its meta on a get.&nbsp; "object" which will check its metas do various meta actions for you and will return found functions as methods.&nbsp; "raw" which ignores its meta.&nbsp; (There might be some bugs in my differentiation of "object" vs "default" .. these will have to be fixed.)

Feedback requested before I commit this.&nbsp; I'm thinking this one is looking pretty good ...

-Phil

Index: tinypy/ops.c
===================================================================
--- tinypy/ops.c        (revision 49)
+++ tinypy/ops.c        (working copy)
@@ -1,13 +1,3 @@
-#define TP_META_BEGIN(self,name) \
-    if (self.dict.dtype &amp;&amp; self.dict.val-&gt;meta.type != TP_NONE) { \
-        int n = _tp_dict_find(tp,self.dict.val-&gt;meta.dict.val,tp_string(name)); \
-        if (n != -1) { \
-            tp_obj meta = self.dict.val-&gt;meta.dict.val-&gt;items[n].val;
-
-#define TP_META_END \
-        } \
-    }
-
 tp_obj tp_str(TP,tp_obj self) {
     int type = self.type;
     if (type == TP_STRING) { return self; }
@@ -80,8 +70,9 @@
     tp_obj r;
     if (type == TP_DICT) {
         TP_META_BEGIN(self,"__get__");
-            return tp_call(tp,meta,tp_params_v(tp,2,self,k));
+            return tp_call(tp,meta,tp_params_v(tp,1,k));
         TP_META_END;
+        if (self.dict.dtype &amp;&amp; _tp_lookup(tp,self,k,&amp;r)) { return r; }
         return _tp_dict_get(tp,self.dict.val,k,"tp_get");
     } else if (type == TP_LIST) {
         if (k.type == TP_NUMBER) {
@@ -176,7 +167,7 @@

     if (type == TP_DICT) {
         TP_META_BEGIN(self,"__set__");
-            tp_call(tp,meta,tp_params_v(tp,3,self,k,v));
+            tp_call(tp,meta,tp_params_v(tp,2,k,v));
             return;
         TP_META_END;
         _tp_dict_set(tp,self.dict.val,k,v);
Index: tinypy/encode.py
===================================================================
--- tinypy/encode.py    (revision 49)
+++ tinypy/encode.py    (working copy)
@@ -470,6 +470,7 @@
     parent = None
     if items[0].type == 'name':
         name = items[0].val
+        parent = Token(tok.pos,'name','object')
     else:
         name = items[0].items[0].val
         parent = items[0].items[1]
@@ -480,22 +481,15 @@
     code(GSET,ts,kls)
     free_tmp(ts) #REG

-    if parent:
-        free_tmp(do(Token(tok.pos,'symbol','=',[
-            Token(tok.pos,'get',None,[
-                Token(tok.pos,'reg',kls),
-                Token(tok.pos,'string','__parent__')]),
-            parent])))
-
+    free_tmp(do(Token(tok.pos,'call',None,[
+        Token(tok.pos,'name','setmeta'),
+        Token(tok.pos,'reg',kls),
+        parent])))
+        
     for fc in items[1].items:
         if fc.type != 'def': continue
         do_def(fc,kls)

-    free_tmp(do(Token(tok.pos,'call',None,[
-        Token(tok.pos,'name','setmeta'),
-        Token(tok.pos,'reg',kls),
-        Token(tok.pos,'name','ClassMeta')])))
-    
     free_reg(kls) #REG

Index: tinypy/tests.py
===================================================================
--- tinypy/tests.py     (revision 49)
+++ tinypy/tests.py     (working copy)
@@ -442,13 +442,6 @@
 """
 ,"OK")

-    t_render("""
-class C:
-    def __init__(self,data): self.data = data
-    def print(self): print(self.data)
-C("OK").print()
-"""
-,"OK")

     t_render("""
 x = [v*v for v in range(0,5)]
@@ -582,22 +575,6 @@
 print(x)
 ""","OK")

-    t_render("""
-class X:
-    pass
-y = X()
-print("OK")
-""","OK")
-
-    t_render("""
-class X: pass
-def test(): y = X()
-test()
-print("OK")
-""","OK")
-
-    t_render(["class X: pass\ndef test(): y = X()","import tmp1\ntmp1.test();print('OK')"],"OK")
-    
     t_render("print(len([1,2,3]))","3")

     t_render('if not "?" in "xyz": print("OK")',"OK")
@@ -637,30 +614,8 @@

     #t_render("def test(): print('OK')\n{'__call__':test}()","OK")

-    t_render("""
-class A:
-    def __init__(self):
-        self.a = 'O'
-        self.b = 'x'
-    def test(self):
-        print("KO")
-class B(A):
-    def __init__(self):
-        A.__init__(self)
-        self.b = 'K'
-    def test(self):
-        print(self.a+self.b)
-B().test()
-""","OK")

     t_render("""
-class A:
-    def test(self):
-        print(self)
-A.test("OK")
-""","OK")
-
-    t_render("""
 def test():
     def fnc():
         print("OK")
@@ -722,39 +677,28 @@
     t_render("""
 def get(self,k):
     return k+"K"
-m = {"__get__":get}
-v = {}
-setmeta(v,m)
+v = object()
+v.__get__ = bind(get,v)
 print(v.O)
-"""
-,"OK")
+""",
+"OK")

     t_render("""
 def set(self,k,v):
     self = getraw(self)
     self[k] = v + "K"
-m = {"__set__":set}
-v = {}
-setmeta(v,m)
+v = object()
+v.__set__ = bind(set,v)
 v.x = "O"
 print(v.x)
-"""
-,"OK")
-
-    t_render("""
-m = {"test":"OK"}
-v = {}
-setmeta(v,m)
-print(getmeta(v)["test"])
 """,
 "OK")

     t_render("""
 def call(self,x):
     print(x)
-m = {"__call__":call}
-v = {}
-setmeta(v,m)
+v = object()
+v.__call__ = bind(call,v)
 v("OK")
 """
 ,"OK")
@@ -769,24 +713,12 @@
 print("OK")
 ""","OK")

-
     meta_objs_init = """
-def MyObj_bind(klass,self):
-    if '__parent__' in klass:
-        MyObj_bind(klass.__parent__,self)
-    for k in klass:
-        v = klass[k]
-        if istype(v,'fnc'):
-            self[k] = bind(v,self)
-        else:
-            self[k] = v
-def MyObj_call(klass,*p):
-    self = {}
-    MyObj_bind(klass,self)
-    if '__init__' in self:
-        self.__init__(*p)
+def my_new(klass,*p):
+    self = object()
+    setmeta(self,klass)
+    self.__init__(*p)
     return self
-MyObj = {'__call__':MyObj_call}

 def A_init(self,v):
     if v: print("A_init")
@@ -794,16 +726,14 @@
     print("A_test1")
 def A_test2(self):
     print("A_test2")
-A = {'__init__':A_init,'test1':A_test1,'test2':A_test2}
-setmeta(A,MyObj)
+A = {'__new__':my_new,'__init__':A_init,'test1':A_test1,'test2':A_test2}

 def B_init(self,v):
     if v: print("B_init")
 def B_test2(self):
     print("B_test2")
-B = {'__parent__':A,'__init__':B_init,'test2':B_test2}
-setmeta(B,MyObj)
-
+B = {'__init__':B_init,'test2':B_test2}
+setmeta(B,A)
 """

     t_render(meta_objs_init+"""A(True)""","A_init")
@@ -813,22 +743,85 @@
     t_render(meta_objs_init+"""B(False).test1()""","A_test1")
     t_render(meta_objs_init+"""B(False).test2()""","B_test2")

-    #test that you can make a callable meta object
+    #various class construct use tests
     t_render("""
-class TestMeta:
+class C:
+    def __init__(self,data): self.data = data
+    def print(self): print(self.data)
+C("OK").print()
+"""
+,"OK")
+
+    t_render("""
+class X:
+    pass
+y = X()
+print("OK")
+""","OK")
+
+    t_render("""
+class X: pass
+def test(): y = X()
+test()
+print("OK")
+""","OK")
+
+    t_render(["class X: pass\ndef test(): y = X()","import tmp1\ntmp1.test();print('OK')"],"OK")
+
+    t_render("""
+class A:
+    def __init__(self):
+        self.a = 'O'
+        self.b = 'x'
+    def test(self):
+        print("KO")
+class B(A):
+    def __init__(self):
+        A.__init__(self)
+        self.b = 'K'
+    def test(self):
+        print(self.a+self.b)
+B().test()
+""","OK")
+
+    t_render("""
+class A:
+    def test(self):
+        print(self)
+A.test("OK")
+""","OK")
+
+
+    #test that you can make a callable object
+    t_render("""
+class Test:
+    def __init__(self,v):
+        self.value = v
     def __call__(self):
-        self = getraw(self)
         print(self.value)

-class Test:
-    def __init__(self,value):
-        self.value = value
-        setmeta(self,TestMeta)
-
 x = Test('OK')
 x()
 ""","OK")

+    #test that you can use a __get__
+    t_render("""
+class Test:
+    def __get__(self,k):
+        return k+"K"
+x = Test()
+print(x.O)
+""","OK")
+    #test that you can use __set__
+    t_render("""
+class Test:
+    def __set__(self,k,v):
+        getraw(self)[k] = "O"+v
+x = Test()
+x.v = "K"
+print(x.v)
+""","OK")
+
     #test that exceptions are cleared after they are caught
     #and not repeated
     t_render("""
@@ -845,6 +838,35 @@
     pass
 ""","OK")

+    #check that missing attributes throw an error
+    t_render("""
+class A: pass
+try:
+    A().x
+except:
+    print('OK')
+""","OK")
+
+    #check that a changed attribute gets changed
+    t_render("""
+class A:
+    def x(self): pass
+a = A()
+a.x = "OK"
+print(a.x)
+""","OK")
+    
+    #test that you can use a __get__ gets inherited
+    t_render("""
+class A:
+    def __get__(self,k):
+        return k+"K"
+class B(A):
+    pass
+x = B()
+print(x.O)
+""","OK")
+
 ########################################################################### #####

 def t_boot(ss,ex,exact=True):
@@ -969,11 +991,9 @@

     /* create our class */
     tp_obj tmp;
-    tp_obj A = tp_dict(tp);
+    tp_obj A = tp_class(tp);
...

read more »

  meta41.patch
21K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Phil Hassey  
View profile  
 More options Jun 11 2008, 1:42 pm
From: Phil Hassey <philhas...@yahoo.com>
Date: Wed, 11 Jun 2008 10:42:52 -0700 (PDT)
Local: Wed, Jun 11 2008 1:42 pm
Subject: Re: [tinypy] Re: Final meta patch

P.S. I learned something new about python today!

http://www.philhassey.com/blog/2008/06/11/learning-python-by-reinvent...

--- On Tue, 6/10/08, Phil Hassey &lt;philhas...@yahoo.com&gt; wrote:
From: Phil Hassey &lt;philhas...@yahoo.com&gt;
Subject: [tinypy] Re: Final meta patch
To: tinypy@googlegroups.com
Date: Tuesday, June 10, 2008, 8:47 PM

I've patched the hole I alluded to in the previous post ...&nbsp; I think the three "kinds" of dicts are now properly distinct.

Allefant - take a good look at this patch, I think it does everything you want, cleanly and quickly.

-Phil

--- On Tue, 6/10/08, Phil Hassey &lt;philhas...@yahoo.com&gt; wrote:
From: Phil Hassey &lt;philhas...@yahoo.com&gt;
Subject: [tinypy] Final meta patch
To: tinypy@googlegroups.com
Date: Tuesday, June 10, 2008, 6:49 PM

Hey,

So .. here's another class / meta patch.&nbsp; This one combines the "best of the best" from all the previous approaches.

- In python code, you can write really clean class interfaces (like in the python style patch).
- You also get a getmeta / setmeta function which you can use to change the "class" of an object.&nbsp; Or even change the parent class of a class.&nbsp; Or whatever.
- You can change methods on a class "real-time" and the objects will "reflect" those changes since methods are looked-up at request.
- Memory use is reduced for objects with dozens of methods as these methods aren't all created upon instantiation of an object.
- Speed increase
 is only 10%, which is quite good.
- Internally
 dicts can be in any of 3 states: "default" which will check its meta on a get.&nbsp; "object" which will check its metas do various meta actions for you and will return found functions as methods.&nbsp; "raw" which ignores its meta.&nbsp; (There might be some bugs in my differentiation of "object" vs "default" .. these will have to be fixed.)

Feedback requested before I commit this.&nbsp; I'm thinking this one is looking pretty good ...

-Phil

Index: tinypy/ops.c
===================================================================
--- tinypy/ops.c        (revision 49)
+++ tinypy/ops.c        (working copy)
@@ -1,13 +1,3 @@
-#define TP_META_BEGIN(self,name) \
-    if (self.dict.dtype &amp;&amp; self.dict.val-&gt;meta.type != TP_NONE) { \
-        int n = _tp_dict_find(tp,self.dict.val-&gt;meta.dict.val,tp_string(name)); \
-        if (n != -1) { \
-            tp_obj meta = self.dict.val-&gt;meta.dict.val-&gt;items[n].val;
-
-#define TP_META_END \
-        } \
-    }
-
 tp_obj tp_str(TP,tp_obj self) {
     int type = self.type;
     if (type == TP_STRING) { return self; }
@@ -80,8 +70,9 @@
     tp_obj r;
     if (type == TP_DICT) {
         TP_META_BEGIN(self,"__get__");
-            return tp_call(tp,meta,tp_params_v(tp,2,self,k));
+            return tp_call(tp,meta,tp_params_v(tp,1,k));
         TP_META_END;
+        if (self.dict.dtype &amp;&amp; _tp_lookup(tp,self,k,&amp;r)) { return r; }
         return _tp_dict_get(tp,self.dict.val,k,"tp_get");
     } else if (type == TP_LIST) {
         if (k.type == TP_NUMBER) {
@@ -176,7 +167,7 @@

     if (type == TP_DICT) {
         TP_META_BEGIN(self,"__set__");
-            tp_call(tp,meta,tp_params_v(tp,3,self,k,v));
+            tp_call(tp,meta,tp_params_v(tp,2,k,v));
             return;
         TP_META_END;
         _tp_dict_set(tp,self.dict.val,k,v);
Index: tinypy/encode.py
===================================================================
--- tinypy/encode.py    (revision 49)
+++ tinypy/encode.py    (working copy)
@@ -470,6 +470,7 @@
     parent = None
     if items[0].type == 'name':
         name = items[0].val
+        parent = Token(tok.pos,'name','object')
     else:
         name = items[0].items[0].val
         parent = items[0].items[1]
@@ -480,22 +481,15 @@
     code(GSET,ts,kls)
     free_tmp(ts) #REG

-    if parent:
-        free_tmp(do(Token(tok.pos,'symbol','=',[
-            Token(tok.pos,'get',None,[
-                Token(tok.pos,'reg',kls),
-                Token(tok.pos,'string','__parent__')]),
-            parent])))
-
+    free_tmp(do(Token(tok.pos,'call',None,[
+        Token(tok.pos,'name','setmeta'),
+        Token(tok.pos,'reg',kls),
+        parent])))
+        
     for fc in items[1].items:
         if fc.type != 'def': continue
         do_def(fc,kls)

-    free_tmp(do(Token(tok.pos,'call',None,[
-        Token(tok.pos,'name','setmeta'),
-        Token(tok.pos,'reg',kls),
-        Token(tok.pos,'name','ClassMeta')])))
-    
     free_reg(kls) #REG

Index: tinypy/tests.py
===================================================================
--- tinypy/tests.py     (revision 49)
+++ tinypy/tests.py     (working copy)
@@ -442,13 +442,6 @@
 """
 ,"OK")

-    t_render("""
-class C:
-    def __init__(self,data): self.data = data
-    def print(self): print(self.data)
-C("OK").print()
-"""
-,"OK")

     t_render("""
 x = [v*v for v in range(0,5)]
@@ -582,22 +575,6 @@
 print(x)
 ""","OK")

-    t_render("""
-class X:
-    pass
-y = X()
-print("OK")
-""","OK")
-
-    t_render("""
-class X: pass
-def test(): y = X()
-test()
-print("OK")
-""","OK")
-
-    t_render(["class X: pass\ndef test(): y = X()","import tmp1\ntmp1.test();print('OK')"],"OK")
-    
     t_render("print(len([1,2,3]))","3")

     t_render('if not "?" in "xyz": print("OK")',"OK")
@@ -637,30 +614,8 @@

     #t_render("def test(): print('OK')\n{'__call__':test}()","OK")

-    t_render("""
-class A:
-    def __init__(self):
-        self.a = 'O'
-        self.b = 'x'
-    def test(self):
-        print("KO")
-class B(A):
-    def __init__(self):
-        A.__init__(self)
-        self.b = 'K'
-    def test(self):
-        print(self.a+self.b)
-B().test()
-""","OK")

     t_render("""
-class A:
-    def test(self):
-        print(self)
-A.test("OK")
-""","OK")
-
-    t_render("""
 def test():
     def fnc():
         print("OK")
@@ -722,39 +677,28 @@
     t_render("""
 def get(self,k):
     return k+"K"
-m = {"__get__":get}
-v = {}
-setmeta(v,m)
+v = object()
+v.__get__ = bind(get,v)
 print(v.O)
-"""
-,"OK")
+""",
+"OK")

     t_render("""
 def set(self,k,v):
     self = getraw(self)
     self[k] = v + "K"
-m = {"__set__":set}
-v = {}
-setmeta(v,m)
+v = object()
+v.__set__ = bind(set,v)
 v.x = "O"
 print(v.x)
-"""
-,"OK")
-
-    t_render("""
-m = {"test":"OK"}
-v = {}
-setmeta(v,m)
-print(getmeta(v)["test"])
 """,
 "OK")

     t_render("""
 def call(self,x):
     print(x)
-m = {"__call__":call}
-v = {}
-setmeta(v,m)
+v = object()
+v.__call__ = bind(call,v)
 v("OK")
 """
 ,"OK")
@@ -769,24 +713,12 @@
 print("OK")
 ""","OK")

-
     meta_objs_init = """
-def MyObj_bind(klass,self):
-    if '__parent__' in klass:
-        MyObj_bind(klass.__parent__,self)
-    for k in klass:
-        v = klass[k]
-        if istype(v,'fnc'):
-            self[k] = bind(v,self)
-        else:
-            self[k] = v
-def MyObj_call(klass,*p):
-    self = {}
-    MyObj_bind(klass,self)
-    if '__init__' in self:
-        self.__init__(*p)
+def my_new(klass,*p):
+    self = object()
+    setmeta(self,klass)
+    self.__init__(*p)
     return self
-MyObj = {'__call__':MyObj_call}

 def A_init(self,v):
     if v: print("A_init")
@@ -794,16 +726,14 @@
     print("A_test1")
 def A_test2(self):
     print("A_test2")
-A = {'__init__':A_init,'test1':A_test1,'test2':A_test2}
-setmeta(A,MyObj)
+A = {'__new__':my_new,'__init__':A_init,'test1':A_test1,'test2':A_test2}

 def B_init(self,v):
     if v: print("B_init")
 def B_test2(self):
     print("B_test2")
-B = {'__parent__':A,'__init__':B_init,'test2':B_test2}
-setmeta(B,MyObj)
-
+B = {'__init__':B_init,'test2':B_test2}
+setmeta(B,A)
 """

     t_render(meta_objs_init+"""A(True)""","A_init")
@@ -813,22 +743,85 @@
     t_render(meta_objs_init+"""B(False).test1()""","A_test1")
     t_render(meta_objs_init+"""B(False).test2()""","B_test2")

-    #test that you can make a callable meta object
+    #various class construct use tests
     t_render("""
-class TestMeta:
+class C:
+    def __init__(self,data): self.data = data
+    def print(self): print(self.data)
+C("OK").print()
+"""
+,"OK")
+
+    t_render("""
+class X:
+    pass
+y = X()
+print("OK")
+""","OK")
+
+    t_render("""
+class X: pass
+def test(): y = X()
+test()
+print("OK")
+""","OK")
+
+    t_render(["class X: pass\ndef test(): y = X()","import tmp1\ntmp1.test();print('OK')"],"OK")
+
+    t_render("""
+class A:
+    def __init__(self):
+        self.a = 'O'
+        self.b = 'x'
+    def test(self):
+        print("KO")
+class B(A):
+    def __init__(self):
+        A.__init__(self)
+        self.b = 'K'
+    def test(self):
+        print(self.a+self.b)
+B().test()
+""","OK")
+
+    t_render("""
+class A:
+    def test(self):
+        print(self)
+A.test("OK")
+""","OK")
+
+
+    #test that you can make a callable object
+    t_render("""
+class Test:
+    def __init__(self,v):
+        self.value = v
     def __call__(self):
-        self = getraw(self)
         print(self.value)

-class Test:
-    def __init__(self,value):
-        self.value = value
-        setmeta(self,TestMeta)
-
 x = Test('OK')
 x()
 ""","OK")

+    #test that you can use a __get__
+    t_render("""
+class Test:
+    def __get__(self,k):
+        return k+"K"
+x = Test()
+print(x.O)
+""","OK")
+    #test that you can use __set__
+    t_render("""
+class Test:
+    def __set__(self,k,v):
+        getraw(self)[k] = "O"+v
+x = Test()
+x.v = "K"
+print(x.v)
+""","OK")
+
     #test that exceptions are cleared after they are caught
     #and not repeated
     t_render("""
@@ -845,6 +838,35 @@
     pass
 ""","OK")

+    #check that missing attributes throw an error
+    t_render("""
+class A: pass
+try:
+    A().x
+except:
+    print('OK')
+""","OK")
+
+    #check that a changed attribute gets changed
+    t_render("""
+class A:
+    def x(self): pass
+a = A()
+a.x = "OK"
+print(a.x)
+""","OK")
+    
+    #test that you can use a __get__ gets inherited
+    t_render("""
+class A:
+    def
...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
allefant  
View profile  
 More options Jun 12 2008, 12:24 pm
From: allefant <allef...@gmail.com>
Date: Thu, 12 Jun 2008 09:24:55 -0700 (PDT)
Local: Thurs, Jun 12 2008 12:24 pm
Subject: Re: Final meta patch
On Jun 11, 4:47 am, Phil Hassey <philhas...@yahoo.com> wrote:

> I've patched the hole I alluded to in the previous post ...&nbsp; I think the three "kinds" of dicts are now properly distinct.

> Allefant - take a good look at this patch, I think it does everything you want, cleanly and quickly.

Yes,  this is just what I wanted :) I.e., Python style run-time
lookup. But I think, I shouldn't be the one to approve it or not,
others here most likely know a lot more about Python and scripting
languages. But then, I guess being closer to Python generally will be
considered good :)

Btw., What did you change to have it work faster? Looking at the
patch, there's apparently no trick like caching anything involved this
time..

About the setmeta, do I understand this right..
- for a class, it will set the parent class
- for an object, it will set the class
?

In which case, it seems to be an ideal solution. I think I remember
that someone already hinted about a solution like this at some point,
when asking about the difference of __class__ and __parent__...

PS: Replying to this post over the web interface was quite hard,
because it's in the middle of two 10 page posts.. see here:
http://groups.google.com/group/tinypy/browse_thread/thread/6fffa1ceca...
:P


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Phil Hassey  
View profile  
 More options Jun 13 2008, 1:08 am
From: Phil Hassey <philhas...@yahoo.com>
Date: Thu, 12 Jun 2008 22:08:49 -0700 (PDT)
Local: Fri, Jun 13 2008 1:08 am
Subject: Re: [tinypy] Re: Final meta patch

Hmn, maybe you could file a complaint with google about how the google groups web interface works?&nbsp; Or subscribe as a mailing list?

In my previous python style patch, the class / parent were actually members of the dictionary, so all lookups took 2-3x as many checks to resolve.&nbsp; By having a "meta" variable in the dict structure, it cuts out a lot of nonsense.

-Phil

--- On Thu, 6/12/08, allefant &lt;allef...@gmail.com&gt; wrote:
From: allefant &lt;allef...@gmail.com&gt;
Subject: [tinypy] Re: Final meta patch
To: "tinypy" &lt;tinypy@googlegroups.com&gt;
Date: Thursday, June 12, 2008, 10:24 AM

On Jun 11, 4:47 am, Phil Hassey &lt;philhas...@yahoo.com&gt; wrote:
&gt; I've patched the hole I alluded to in the previous post ...&amp;nbsp;
I think the three "kinds" of dicts are now properly distinct.
&gt;
&gt; Allefant - take a good look at this patch, I think it does everything you
want, cleanly and quickly.
&gt;

Yes,  this is just what I wanted :) I.e., Python style run-time
lookup. But I think, I shouldn't be the one to approve it or not,
others here most likely know a lot more about Python and scripting
languages. But then, I guess being closer to Python generally will be
considered good :)

Btw., What did you change to have it work faster? Looking at the
patch, there's apparently no trick like caching anything involved this
time..

About the setmeta, do I understand this right..
- for a class, it will set the parent class
- for an object, it will set the class
?

In which case, it seems to be an ideal solution. I think I remember
that someone already hinted about a solution like this at some point,
when asking about the difference of __class__ and __parent__...

PS: Replying to this post over the web interface was quite hard,
because it's in the middle of two 10 page posts.. see here:
http://groups.google.com/group/tinypy/browse_thread/thread/6fffa1ceca...
:P


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
illume  
View profile  
 More options Jun 17 2008, 9:50 pm
From: illume <ren...@gmail.com>
Date: Tue, 17 Jun 2008 18:50:31 -0700 (PDT)
Local: Tues, Jun 17 2008 9:50 pm
Subject: Re: Final meta patch
How about using the __class__ assignment like how python does it?
Rather than a different set/get?

On Jun 13, 3:08 pm, Phil Hassey <philhas...@yahoo.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »