# HG changeset patch # User Paul Boddie # Date 1235089454 -3600 # Node ID 80ddd8db26120ae048719a72d47335ec4e5de276 # Parent 41f297e7800c84f4607e5b351d86922c290e2b0d Improved context-related documentation and related tests. Added a document about assignment and access. diff -r 41f297e7800c -r 80ddd8db2612 docs/assignment.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/assignment.txt Fri Feb 20 01:24:14 2009 +0100 @@ -0,0 +1,22 @@ +Assignment types: + + Assignment of stored value to... Effect on context + -------------------------------- ----------------- + local preserved + global (module) preserved + class preserved + instance preserved + + Assignment to a namespace preserves the context + +Access types: + + Access to stored value from... Effect on context Optimised instruction Unoptimised instruction + ------------------------------ ----------------- --------------------- ----------------------- + local preserved LoadName + global (module) preserved LoadAddress LoadAttrIndex + class preserved LoadAddress LoadAttrIndex + class via instance overridden LoadAddressContext LoadAttrIndex + instance preserved LoadAttr LoadAttrIndex + + Access to a namespace may not preserve the stored context diff -r 41f297e7800c -r 80ddd8db2612 docs/structures.txt --- a/docs/structures.txt Mon Feb 09 01:09:42 2009 +0100 +++ b/docs/structures.txt Fri Feb 20 01:24:14 2009 +0100 @@ -73,34 +73,31 @@ LoadAddress Load attribute from Classes, functions and modules known object cause the loaded attribute to be - retrieved unchanged; whereas - constants (representing instances) + (typically classes and retrieved unchanged; whereas + modules) constants (representing instances) cause the constant to override the attribute's own context (since all attributes should belong to the constant's class hierarchy) - LoadAddressContext Override loaded context with a - predetermined object (provided - that the object and context are - compatible, which can be tested at + LoadAddressContext Load attribute Override loaded context with a + from known object predetermined object (provided + (typically classes) that the object and context are + for an instance compatible, which can be tested at compile-time) - LoadAttr Load attribute from Attributes with null contexts or - instance contexts compatible with the - instance cause loaded attributes - to combine the instance as context - with the object from the - attribute; other attributes have - their context preserved + LoadAttr Load attribute from Contexts are preserved (since only + instance values stored on instances can be + accessed in this way, and their + contexts would never be overridden + upon access - LoadAttrIndex Load attribute from Functions and modules as unknown - object the unknown object accessor cause - the loaded attribute to be - retrieved unchanged; classes and - instances cause the LoadAttr rules - to apply (class compatibility - applies) + LoadAttrIndex Load attribute from Classes, functions and modules as + object (can be the unknown object accessor cause + classes, modules, the loaded attribute to be + instances...) retrieved unchanged; instances + cause the LoadAttr rules to apply + (class compatibility applies) A certain amount of run-time testing might be required for both LoadAttr and LoadAttrIndex instructions. However, with certain restrictions in place around @@ -152,6 +149,8 @@ necessary in order to prevent assignments to classes +Note that contexts are never changed in the stored value: they are preserved. + Objects ------- diff -r 41f297e7800c -r 80ddd8db2612 tests/attributes2.py --- a/tests/attributes2.py Mon Feb 09 01:09:42 2009 +0100 +++ b/tests/attributes2.py Fri Feb 20 01:24:14 2009 +0100 @@ -15,6 +15,8 @@ self.e(1) # TypeError: unbound C.e needs C instance, not int class E(C): + # e = C.e (via inheritance) + def test(self): self.e() diff -r 41f297e7800c -r 80ddd8db2612 tests/reference/methods.py --- a/tests/reference/methods.py Mon Feb 09 01:09:42 2009 +0100 +++ b/tests/reference/methods.py Fri Feb 20 01:24:14 2009 +0100 @@ -5,20 +5,20 @@ class B: def f(self): - pass + print self -def f(x): - pass +def f(self): + print self b = B() - # on A on a -A.f1 = f # unbound bound (a) -A.f2 = B.f # unbound unbound -A.f3 = b.f # bound (b) bound (b) + # on A on a context on A attribute context on a attribute +A.f1 = f # unbound bound (a) A a +A.f2 = B.f # unbound unbound B (need B instance) B (need B instance) +A.f3 = b.f # bound (b) bound (b) b b a = A() -a.f4 = f # N/A function -a.f5 = B.f # N/A unbound -a.f6 = b.f # N/A bound (b) +a.f4 = f # N/A function N/A none +a.f5 = B.f # N/A unbound N/A B (need B instance) +a.f6 = b.f # N/A bound (b) N/A b # vim: tabstop=4 expandtab shiftwidth=4