# HG changeset patch # User Paul Boddie # Date 1236210342 -3600 # Node ID ad0b88c81a1f202a199b9edc23022be3cef970e0 # Parent 2066cb2e583ed5ebae2bbde2d9d51986e3a7d27a Added more notes about, and a test of, class attribute context behaviour. diff -r 2066cb2e583e -r ad0b88c81a1f docs/assignment.txt --- a/docs/assignment.txt Mon Mar 02 00:04:55 2009 +0100 +++ b/docs/assignment.txt Thu Mar 05 00:45:42 2009 +0100 @@ -47,11 +47,13 @@ local preserved LoadName global (module) preserved LoadAddress LoadAttrIndex class preserved LoadAddress LoadAttrIndex - class via instance overridden LoadAddressContext LoadAttrIndex + class via instance overridden LoadAddressContext (*) LoadAttrIndex (*) instance preserved LoadAttr LoadAttrIndex Access to a namespace may not preserve the stored context + (*) Other modes of these instructions may exist for certain optimisations + Access to class attributes via instances: Access to stored value with... Effect on context @@ -64,6 +66,20 @@ LoadAddressContext and LoadAttrIndex must therefore check whether the context must be overridden +Optimisation possibilities: + + Class Class attribute Context of attribute Instruction + ----- --------------- -------------------- ----------- + known constant preserved LoadAddress + known constant overridden LoadAddressContext + known not constant preserved LoadAddress (attribute may always be preserved) + known not constant overridden LoadAddressContext (attribute may always be overridden) + known not constant not known LoadAddressContextCond + not known not known preserved LoadAttrIndex (attribute may have preserved context in all classes) + not known not known overridden LoadAttrIndexContext (attribute may have overridden context in all classes) + not known not known not known LoadAttrIndexContextCond + Since the object table encodes sufficient information (an instance must be compatible to access the class attribute, and compatibility information is - stored), an explicit compatibility test is not required at run-time + stored), an explicit compatibility test may not always be required at + run-time diff -r 2066cb2e583e -r ad0b88c81a1f tests/attributes_class_multiple.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attributes_class_multiple.py Thu Mar 05 00:45:42 2009 +0100 @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +class C: + clsattr = 123 + clsattr = 456 + +a = C +b = C.clsattr + +# vim: tabstop=4 expandtab shiftwidth=4