# HG changeset patch # User Paul Boddie # Date 1304895395 -7200 # Node ID 6e610d3058f183bc0418c6fcfe8e9bc1cf0f8bf5 # Parent 0044fb55ab2b46e8a92336148148a8d94559782c Added tests of method assignment to classes plus notes about work to be done. diff -r 0044fb55ab2b -r 6e610d3058f1 TO_DO.txt --- a/TO_DO.txt Sun May 08 22:15:28 2011 +0200 +++ b/TO_DO.txt Mon May 09 00:56:35 2011 +0200 @@ -1,9 +1,16 @@ +Class and Module Attribute Assignment +===================================== + +Verify that the context information is correctly set, particularly for the unoptimised +cases. + + Allow module types to be tested in guards. + + Update docs/assignment.txt. + Dynamic Attribute Access ======================== -Ensure that getattr (or other dynamic attribute usage) causes propagation of coverage to -the potential attributes. - Consider explicit accessor initialisation. Attribute Usage diff -r 0044fb55ab2b -r 6e610d3058f1 micropython/trans.py --- a/micropython/trans.py Sun May 08 22:15:28 2011 +0200 +++ b/micropython/trans.py Mon May 09 00:56:35 2011 +0200 @@ -340,6 +340,7 @@ obj = self.objtable.access(target_name, target_name) # Where no attribute entry exists, the target could be a module. + # NOTE: Should perhaps raise an error. except TableError, exc: print "Possible guard for", target_name, "not enforceable." diff -r 0044fb55ab2b -r 6e610d3058f1 tests/attributes_class_assignment_method.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attributes_class_assignment_method.py Mon May 09 00:56:35 2011 +0200 @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +class C: + def clsattr(self): + return 123 + def clsattr2(self): + return 456 + +def a(x): + return 789 + +def b(x): + return 234 + +C.clsattr = a +C.clsattr2 = b + +c = C() + +result_789 = c.clsattr() +result_234 = c.clsattr2() + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 0044fb55ab2b -r 6e610d3058f1 tests/failure/attributes_class_assignment_method.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/failure/attributes_class_assignment_method.py Mon May 09 00:56:35 2011 +0200 @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +class C: + def clsattr(self): + return 123 + def clsattr2(self): + return 456 + +def a(x): + return 789 + +def b(x): + return 234 + +C.clsattr = a +C.clsattr2 = b + +c = C() + +result_789 = c.a() +result_234 = c.b() + +# vim: tabstop=4 expandtab shiftwidth=4