New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
experimental support for extended slicing on lists #32655
Comments
No description provided. |
this 10 minute hack adds support for "extended slicing" to lists, by which I mean things like: >>> range(100)[23:60:12]
[23, 35, 47, 59] todo: |
c'mon michael! at least get *some* of the boundary cases... |
negative indices! for i in listvar[::-1]:
pass now iterates over the list backwards (rather than coredumping...) |
updated patch to support slice assignements, deletions |
bugfixes (refounting in assignment, logic in deletion) & a few tweaks. |
meep! naughty Michael hadn't been running "make test" often enough. |
Note that without doc and test patches too, and Real Soon, I'll have to Postpone this. Assigned to me to remind me of that. |
OK, I'll get to that soon (ie. <24hours, hopefully <4). I may need some advice for the docs... |
So, I missed my deadline by twenty five minutes. Sorry :-) This latest patch adds a fairly basic test suite, a stab at some docs, and jumps up and down on PySlice_GetIndices. Also (wrt. stringobject.c & unicodeobject.c) it's amazing what you can break, isn't it? Thank God for test suites... |
1 similar comment
So, I missed my deadline by twenty five minutes. Sorry :-) This latest patch adds a fairly basic test suite, a stab at some docs, and jumps up and down on PySlice_GetIndices. Also (wrt. stringobject.c & unicodeobject.c) it's amazing what you can break, isn't it? Thank God for test suites... |
Too late for the release, sorry. And Tim hates negative strides. We'll get back to this for 2.1. |
Is reviewing and applying this patch the best use of my time? I note that this is okay, but low priority -- I doubt that it will get used much. Plus, what about the array module, strings, UserList? |
Rejected for lack of interest. Sorry, Michael! |
Logged In: YES Michael, the tide has changed. Would you be interested in It could possibly help to address bug 473985 and maybe also If you have no time, let me know and I'll see if I can find |
Logged In: YES Whoosh, this is a blast from the past. I've minimally updated the patch (it only failed to apply Suffice to say I don't really remember how this works :-/ What more needs to be done? strings, arrays (shouldn't be |
Logged In: YES Go ahead and check it in. Strings and unicode also need to support slices. While I think array needs more work -- first 'array.array' should Off-topic aside: the change you had to make to |
Logged In: YES (I lied about array -- it is already a subclassable |
Logged In: YES Hmm, I'm now older and more cowardly than when I wrote this, This patch changes the behaviour of PySlice_GetIndices, Do you really want assignments to extended slices in lists? |
Logged In: YES
The big change is that it now can set an exception. I think You can call PyInt_AsLong on any object, and if it has a The check for *step==0 could come earlier.
They're about as useful as getting an extended slice from a |
Logged In: YES I checked the Numeric-21.0 source, and they don't use I also checked the numarray-0.3.3 source, and they don't do So I think we're safe fixing PySlice_GetIndices. However, I think there's a bug in your code. Suppose a is |
Logged In: YES Hmm. In my working copy, PySlice_GetIndicesEx now has a Yes, I was staring at my code and thinking "that can't get |
Logged In: YES OK, sounds good. (BTW, a Google search for |
Logged In: YES That message was from me :) |
Logged In: YES Yes, I said so ("from you"). :) That's why it was so ironic |
Logged In: YES Doh, it's me that can't read, not you... |
Logged In: YES OK, I think the attached gets all the cases right. I've also implemented extended slicing for strings and I think this is ready to go, at last. |
Logged In: YES Wow. Good job on the docs! (Although personally I would have In test_bool.py, Some lines added to listobject.c (e.g. in But please do check it in, correcting the nits as you go! |
Logged In: YES Re footnotes: wimp! Re long lines: there's still one longish line in But this is now checked in (with mild modfications from the Doc/api/concrete.tex revision 1.16 |
Logged In: YES a very far-fetched bug... >>> slice(-3058, 0, -1).indices(20)
(-1, 5, -1)
>>> slice(-30589138798749473891743819L, 0, -1).indices(20)
(0, 5, -1) this is due to _PyEval_SliceIndex() which "rounds" very large negative |
Logged In: YES a comedy of errors! i'll fix this soon. |
Logged In: YES Heh. I'd actually intended to change _PyEval_SliceIndex to Fixed in Python/ceval.c revision 2.352. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: