From 54757b83165d95bd19ceda0a67e952374546e398 Mon Sep 17 00:00:00 2001 From: Nicolas Dandrimont Date: Tue, 25 Jun 2013 20:08:12 +0200 Subject: [PATCH] Slicing a HyList makes the same kind of object again --- hy/models/list.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hy/models/list.py b/hy/models/list.py index d2d4da7..e45e40b 100644 --- a/hy/models/list.py +++ b/hy/models/list.py @@ -36,5 +36,16 @@ class HyList(HyObject, list): def __add__(self, other): return self.__class__(super(HyList, self).__add__(other)) + def __getslice__(self, start, end): + return self.__class__(super(HyList, self).__getslice__(start, end)) + + def __getitem__(self, item): + ret = super(HyList, self).__getitem__(item) + + if isinstance(item, slice): + return self.__class__(ret) + + return ret + def __repr__(self): return "[%s]" % (" ".join([repr(x) for x in self]))