2011-03-20 | Paul Boddie | file changeset files shortlog | Added support in the code generation for class attribute assignment, introducing optimisation-related configuration of the support depending on whether attribute usage is being tracked. Prevented __class__ attribute assignment if detected at compile-time. Added run-time support for class attribute assignment. Added registration of instance attribute usage upon assignment. Added a special attribute to exception instances, protecting it from vacuuming. Fixed a test of class attribute assignment so that it can be run successfully. |
paul@404 | 1 | #!/usr/bin/env python |
paul@404 | 2 | |
paul@404 | 3 | class C: |
paul@404 | 4 | clsattr = 123 |
paul@404 | 5 | clsattr2 = 456 |
paul@404 | 6 | |
paul@404 | 7 | class D: |
paul@404 | 8 | clsattr = 321 |
paul@404 | 9 | |
paul@405 | 10 | def f(cls, x): |
paul@404 | 11 | cls.clsattr = 789 |
paul@405 | 12 | if x: |
paul@404 | 13 | cls.clsattr2 = 234 |
paul@404 | 14 | |
paul@405 | 15 | f(C, 1) |
paul@405 | 16 | f(D, 0) # prevent AttributeError |
paul@404 | 17 | |
paul@405 | 18 | result1_789 = C.clsattr |
paul@405 | 19 | result1_234 = C.clsattr2 |
paul@405 | 20 | result2_789 = D.clsattr |
paul@404 | 21 | |
paul@404 | 22 | # vim: tabstop=4 expandtab shiftwidth=4 |