Lichen

tests/nested_calls.py

934:2989aab1b4f7
7 months ago Paul Boddie Renamed the utf8string class to unicode, eliminating the unicode function. This means that the simple case of merely returning an object if it is already a Unicode object no longer occurs when using the unicode callable, but such behaviour might be better supported with more general customised instantiation functionality.
     1 class C:     2     def __init__(self, x):     3         self.x = x     4      5     def value(self):     6         return self.x     7      8     def length(self):     9         return self.double(self.value())    10     11     def double(self, x):    12         return x * 2    13     14 c = C(3)    15 print c.length()                        # 6    16     17 # Explicit function for addition purposes.    18     19 def combine(x, y, z):    20     return x + y + z    21     22 class Tree:    23     def __init__(self, item, left=None, right=None):    24         self.item = item    25         self.left = left    26         self.right = right    27     28     def count(self):    29         if self.left and self.right:    30             # Test calls in parameter lists needing separate temporary storage.    31             return combine(self.item, self.left.count(), self.right.count())    32         else:    33             return self.item    34     35 tree = \    36     Tree(10000,    37         Tree(2000,    38             Tree(300),    39             Tree(40)    40             ),    41         Tree(5))    42     43 print tree.count()                      # 12345