1.1 --- a/lib/__builtins__/tuple.py Wed Nov 23 17:23:52 2016 +0100
1.2 +++ b/lib/__builtins__/tuple.py Wed Nov 23 17:32:58 2016 +0100
1.3 @@ -31,23 +31,40 @@
1.4
1.5 "Initialise the tuple."
1.6
1.7 - self.__data__ = native._tuple_init(args, len(args)) # allocate and copy elements
1.8 + # Reserve an attribute for a fragment reference along with some space
1.9 + # for elements.
1.10 +
1.11 + size = args is not None and len(args) or 0
1.12 + self.__data__ = native._list_init(size)
1.13 + native._list_setsize(self, size)
1.14 +
1.15 + # Populate the tuple.
1.16 +
1.17 + if args is not None:
1.18 + i = 0
1.19 + for arg in args:
1.20 + native._list_setelement(self, i, arg)
1.21 + i += 1
1.22
1.23 def __getslice__(self, start, end=None):
1.24
1.25 "Return a slice starting from 'start', with the optional 'end'."
1.26
1.27 - return native._list_to_tuple(get_using(sequence.__getslice__, self)(start, end))
1.28 + return tuple(get_using(sequence.__getslice__, self)(start, end))
1.29
1.30 def __len__(self):
1.31
1.32 "Return the length of the tuple."
1.33
1.34 - return native._tuple_len(self)
1.35 + return native._list_len(self)
1.36
1.37 def __add__(self, other): pass
1.38
1.39 - def __str__(self): pass
1.40 + def __str__(self):
1.41 +
1.42 + "Return a string representation."
1.43 +
1.44 + return self._str("(", ")")
1.45
1.46 __repr__ = __str__
1.47
1.48 @@ -66,6 +83,18 @@
1.49 # Special implementation methods.
1.50
1.51 def __get_single_item__(self, index):
1.52 - return native._tuple_element(self, index)
1.53 +
1.54 + "Return the item at the normalised (positive) 'index'."
1.55 +
1.56 + if index >= len(self):
1.57 + raise IndexError(index)
1.58 +
1.59 + return native._list_element(self, index)
1.60 +
1.61 + def __set_single_item__(self, index, value):
1.62 +
1.63 + "Set at the normalised (positive) 'index' the given 'value'."
1.64 +
1.65 + raise TypeError(self)
1.66
1.67 # vim: tabstop=4 expandtab shiftwidth=4