1.1 --- a/lib/builtins.py Sat Sep 04 00:55:37 2010 +0200
1.2 +++ b/lib/builtins.py Sun Sep 05 02:20:05 2010 +0200
1.3 @@ -292,11 +292,13 @@
1.4
1.5 "Implementation of xrange."
1.6
1.7 - def __init__(self, start_or_end, end=None, step=1):
1.8 + NO_END = object()
1.9 +
1.10 + def __init__(self, start_or_end, end=NO_END, step=1):
1.11
1.12 "Initialise the xrange with the given 'start_or_end', 'end' and 'step'."
1.13
1.14 - if end is None:
1.15 + if end is xrange.NO_END:
1.16 self.start = 0
1.17 self.end = start_or_end
1.18 else:
1.19 @@ -305,7 +307,7 @@
1.20
1.21 self.step = step
1.22 self.current = self.start
1.23 - self.limited = self.end is not None
1.24 + self.limited = self.end is not xrange.NO_END
1.25
1.26 def __iter__(self):
1.27
1.28 @@ -329,7 +331,7 @@
1.29
1.30 "Implementation of slice."
1.31
1.32 - def __init__(self, start_or_end=None, end=None, step=1):
1.33 + def __init__(self, start_or_end=None, end=xrange.NO_END, step=1):
1.34
1.35 "Initialise the slice with the given 'start_or_end', 'end' and 'step'."
1.36
2.1 --- a/micropython/ast.py Sat Sep 04 00:55:37 2010 +0200
2.2 +++ b/micropython/ast.py Sun Sep 05 02:20:05 2010 +0200
2.3 @@ -422,6 +422,10 @@
2.4 args = [compiler.ast.Name("None"), node.upper]
2.5 else:
2.6 args = [node.lower]
2.7 + if node.upper is None:
2.8 + args.append(compiler.ast.Name("None"))
2.9 + else:
2.10 + args.append(node.upper)
2.11
2.12 # NOTE: Need to guarantee reliable access to the slice built-in.
2.13
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tests/call_func_default_class_attribute.py Sun Sep 05 02:20:05 2010 +0200
3.3 @@ -0,0 +1,14 @@
3.4 +#!/usr/bin/env python
3.5 +
3.6 +class C:
3.7 +
3.8 + default = 101
3.9 +
3.10 + def f(self, x=default):
3.11 + return x
3.12 +
3.13 +c = C()
3.14 +result_101 = c.f()
3.15 +result_202 = c.f(202)
3.16 +
3.17 +# vim: tabstop=4 expandtab shiftwidth=4
4.1 --- a/tests/slice.py Sat Sep 04 00:55:37 2010 +0200
4.2 +++ b/tests/slice.py Sun Sep 05 02:20:05 2010 +0200
4.3 @@ -1,9 +1,16 @@
4.4 #!/usr/bin/env python
4.5
4.6 -l = [1, 2, 3, 4, 5]
4.7 +class C:
4.8 + def __getitem__(self, slice):
4.9 + return slice.start
4.10
4.11 -result1_3 = len(l[2:])
4.12 -result_2 = len(l[:2])
4.13 -result2_3 = len(l[1:4])
4.14 +class D:
4.15 + def __getitem__(self, slice):
4.16 + return slice.end
4.17 +
4.18 +c = C()
4.19 +d = D()
4.20 +result_3 = c[3:]
4.21 +result_4 = d[:4]
4.22
4.23 # vim: tabstop=4 expandtab shiftwidth=4
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/tests/slice_list.py Sun Sep 05 02:20:05 2010 +0200
5.3 @@ -0,0 +1,9 @@
5.4 +#!/usr/bin/env python
5.5 +
5.6 +l = [1, 2, 3, 4, 5]
5.7 +
5.8 +result1_3 = len(l[2:])
5.9 +result_2 = len(l[:2])
5.10 +result2_3 = len(l[1:4])
5.11 +
5.12 +# vim: tabstop=4 expandtab shiftwidth=4