[issue14178] _elementtree problem deleting slices with steps != +1
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset 1a721b9a4039 by Eli Bendersky in branch 'default': Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module. http://hg.python.org/cpython/rev/1a721b9a4039 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14178 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14178] _elementtree problem deleting slices with steps != +1
Changes by Eli Bendersky eli...@gmail.com: -- resolution: - fixed stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14178 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14178] _elementtree problem deleting slices with steps != +1
Eli Bendersky eli...@gmail.com added the comment: WRT the ParseError problem, I've opened issue #14207 for it since the problems are quite unrelated. -- title: Failing tests for ElementTree - _elementtree problem deleting slices with steps != +1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14178 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Problem with slices.
I'm for the moment writing two classes. A table, which is like a list, but can start at any integer. A tree which is like a dictionary, but will iterate over the keys in sorted order. The problem is that I would like to implemet slices but, that seems to be impossible with how slices are implemented now. I wrote the following class to test things out. class Tst: def __getitem__(self, key): print key then I called the interpreter and got this: from tst import Tst t=Tst() t[:] slice(0, 2147483647, None) t[:9] slice(0, 9, None) t[:'ok'] slice(None, 'ok', None) t['ok':] slice('ok', None, None) t[6:] slice(6, 2147483647, None) t[1,2] (1, 2) t[1,2:] (1, slice(2, None, None)) t[(1,2):] slice((1, 2), None, None) Now suppose tab is a table with indexes from -5 to 12. tab[:4] would have to make a table ranging from -5 to 4 tab[0:4] would have to make a table ranging from 0 to 4. But each time I would be given the same argument, being slice(0, 4, None). So I would be unable to distinghuish between the two. I don't think it very likely but I could have a table with indexes from 2147483647 to 2147483700, so having 2147483647 as value that indicated till the end of the sequence is a bit awkward. The same problems occur when I have a tree with integer key values. But even if I don't use integers as keys I have a problem with what is returned since None is a valid key and thus it shouldn't be used this way. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with slices.
Antoon Pardon wrote: I'm for the moment writing two classes. A table, which is like a list, but can start at any integer. A tree which is like a dictionary, but will iterate over the keys in sorted order. The problem is that I would like to implemet slices but, that seems to be impossible with how slices are implemented now. I wrote the following class to test things out. class Tst: def __getitem__(self, key): print key then I called the interpreter and got this: from tst import Tst t=Tst() t[:] slice(0, 2147483647, None) t[:9] slice(0, 9, None) t[:'ok'] slice(None, 'ok', None) t['ok':] slice('ok', None, None) t[6:] slice(6, 2147483647, None) t[1,2] (1, 2) t[1,2:] (1, slice(2, None, None)) t[(1,2):] slice((1, 2), None, None) Now suppose tab is a table with indexes from -5 to 12. tab[:4] would have to make a table ranging from -5 to 4 tab[0:4] would have to make a table ranging from 0 to 4. But each time I would be given the same argument, being slice(0, 4, None). So I would be unable to distinghuish between the two. I don't think it very likely but I could have a table with indexes from 2147483647 to 2147483700, so having 2147483647 as value that indicated till the end of the sequence is a bit awkward. The same problems occur when I have a tree with integer key values. But even if I don't use integers as keys I have a problem with what is returned since None is a valid key and thus it shouldn't be used this way. Consider new-style classes: class T(object): ... def __getitem__(self, key): ... return key ... t = T() t[:4] slice(None, 4, None) t[0:4] slice(0, 4, None) t[0:] slice(0, None, None) Peter -- http://mail.python.org/mailman/listinfo/python-list