2016-10-17 | Paul Boddie | file changeset files shortlog | Track attribute assignment in attribute usage in order to restrict accessors. Changed the function type to be separate from all other types, preventing special __fn__ and __args__ attribute shadowing. |
paul@2 | 1 | class C: |
paul@2 | 2 | def __init__(self): |
paul@2 | 3 | self.a = 1 |
paul@2 | 4 | |
paul@2 | 5 | b = 2 |
paul@2 | 6 | |
paul@2 | 7 | class D: |
paul@2 | 8 | def __init__(self): |
paul@2 | 9 | self.a = 3 |
paul@2 | 10 | self.b = 4 |
paul@2 | 11 | |
paul@2 | 12 | class E: |
paul@2 | 13 | a = 5 |
paul@2 | 14 | b = 6 |
paul@2 | 15 | |
paul@2 | 16 | def f(x): |
paul@2 | 17 | return x.a, x.b |
paul@2 | 18 | |
paul@107 | 19 | def g(x): |
paul@107 | 20 | |
paul@107 | 21 | # Should only permit D instance and E. |
paul@107 | 22 | |
paul@107 | 23 | x.a = 7 |
paul@107 | 24 | x.b = 8 |
paul@107 | 25 | |
paul@2 | 26 | c = C() |
paul@2 | 27 | d = D() |
paul@2 | 28 | e = E() |
paul@2 | 29 | |
paul@2 | 30 | result1 = f(c) # (1, 2) |
paul@2 | 31 | result2 = f(d) # (3, 4) |
paul@2 | 32 | result3 = f(e) # (5, 6) |