2021-10-31 | Paul Boddie | raw annotate files changeset graph | Introduced a dedicated integer type based on ssize_t. This allows integers to be used for sizes and lengths in native and low-level operations whilst also supporting their storage in the same amount of space as a pointer, thus avoiding the inflation of attributes that might occur if a larger type were chosen. |
1 class C: 2 def __init__(self, x): 3 self.x = x 4 5 def __str__(self): 6 return "C(%r)" % self.x 7 8 __repr__ = __str__ 9 10 class D: 11 x = 1 12 13 def f(): 14 return D 15 16 c = C(C(1)) # c.x.x = 1 17 print c # C(C(1)) 18 print c.x # C(1) 19 print c.x.x # 1 20 c.x.x = 2 21 print c # C(C(2)) 22 print c.x # C(2) 23 print c.x.x 24 25 print D.x # 1 26 D.x = 2 27 print D.x # 2 28 D.x = C(3) 29 print D.x # C(3) 30 print D.x.x # 3 31 D.x.x = 4 32 print D.x.x # 4 33 34 f().x = 5 35 print D.x # 5