I just noticed List.copy() returns a plain list, as it doesn't override the copy method, and was about to create a PR implementing it. Then I realized this is a deeper issue, so I need your opinion before moving on:
-
list.copy() == list[:], so copy if was changed to preserve type, should slicing be changed too? I.e., should List.__getitem__ use the a similar logic as __setitem__, and do something like this:if isinstance(index, slice): return self.__class__(super().__getitem__(index)).
-
It would be surprising if copy() preserve type but slicing didn't. In one hand, some might expect (and rely on) copy and slicing to return a plain list. OTOH, it's awkward to write b = List[xxx](a.copy()) to preserve type and easy to do b = list(a.copy()) to guarantee a plain list.
-
In a general way, should the mutables Compound and List preserve type in slicing and subsets?
I could do some research to see what numpy.ndarray and other similar list subclasses do, and also if there's any principle suggested in collections.abc.MutableSequence.
Meanwhile, what's your opinion on this? Interested in a PR to implement copy() and related methods in Compound and List?
I just noticed
List.copy()returns a plainlist, as it doesn't override the copy method, and was about to create a PR implementing it. Then I realized this is a deeper issue, so I need your opinion before moving on:list.copy() == list[:], so copy if was changed to preserve type, should slicing be changed too? I.e., shouldList.__getitem__use the a similar logic as__setitem__, and do something like this:if isinstance(index, slice): return self.__class__(super().__getitem__(index)).It would be surprising if
copy()preserve type but slicing didn't. In one hand, some might expect (and rely on) copy and slicing to return a plain list. OTOH, it's awkward to writeb = List[xxx](a.copy())to preserve type and easy to dob = list(a.copy())to guarantee a plain list.In a general way, should the mutables
CompoundandListpreserve type in slicing and subsets?I could do some research to see what
numpy.ndarrayand other similar list subclasses do, and also if there's any principle suggested incollections.abc.MutableSequence.Meanwhile, what's your opinion on this? Interested in a PR to implement
copy()and related methods in Compound and List?