Lichen

Changeset

809:0c893b6761a7
2017-04-11 Paul Boddie raw files shortlog changelog graph Added a test of attribute assignment.
tests/assign_attr.py (file)
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tests/assign_attr.py	Tue Apr 11 18:29:30 2017 +0200
     1.3 @@ -0,0 +1,35 @@
     1.4 +class C:
     1.5 +    def __init__(self, x):
     1.6 +        self.x = x
     1.7 +
     1.8 +    def __str__(self):
     1.9 +        return "C(%r)" % self.x
    1.10 +
    1.11 +    __repr__ = __str__
    1.12 +
    1.13 +class D:
    1.14 +    x = 1
    1.15 +
    1.16 +def f():
    1.17 +    return D
    1.18 +
    1.19 +c = C(C(1)) # c.x.x = 1
    1.20 +print c     # C(C(1))
    1.21 +print c.x   # C(1)
    1.22 +print c.x.x # 1
    1.23 +c.x.x = 2
    1.24 +print c     # C(C(2))
    1.25 +print c.x   # C(2)
    1.26 +print c.x.x
    1.27 +
    1.28 +print D.x   # 1
    1.29 +D.x = 2
    1.30 +print D.x   # 2
    1.31 +D.x = C(3)
    1.32 +print D.x   # C(3)
    1.33 +print D.x.x # 3
    1.34 +D.x.x = 4
    1.35 +print D.x.x # 4
    1.36 +
    1.37 +f().x = 5
    1.38 +print D.x   # 5