-
Notifications
You must be signed in to change notification settings - Fork 803
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
Slicing twice doesn't work #799
Comments
Filed elastic/elasticsearch-dsl-py#799 on the way
Hey @konstin, I've created a branch in my fork with minor changes to support this. Take a look at the tests and let me know - specifically this one. @honzakral, what do you think? |
Hi @lolletsoc, the changes does solve the issue with slicing twice. The behavior for slicing multiple times still doesn't match the expected pythonic behavior though. Even though I doubt anyone uses this in practice, it might be worth fixing it, >>> list(range(0, 100)[10:][:5][5:])
[]
>>> Search()[10:][:5][5:].to_dict()
{'query': {'match_all': {}}, 'from': 15, 'size': 10} |
Yeah, exactly why I pointed you at that test. If we try to mold this around the pythonic way, we're going to end up with |
Thanks for raising this issue @konstin, I understand the confusion. Right now any slicing will reset the That sounds very reasonable to me and I think we should do it, we just need to be careful about documenting it properly since it is a breaking change. Thanks again for bringing it up! 0 - https://github.com/django/django/blob/master/django/db/models/sql/query.py#L1603-L1624 |
* Added support for slicing multiple times in Search class Fixes #799 * simplify slicing logic * A few more slicing unit tests * Removed unnecessary comment * simplified slicing logic even more * added suggested changes * add more slicing examples to documentation
* Added support for slicing multiple times in Search class Fixes #799 * simplify slicing logic * A few more slicing unit tests * Removed unnecessary comment * simplified slicing logic even more * added suggested changes * add more slicing examples to documentation (cherry picked from commit fb57759)
* Added support for slicing multiple times in Search class Fixes #799 * simplify slicing logic * A few more slicing unit tests * Removed unnecessary comment * simplified slicing logic even more * added suggested changes * add more slicing examples to documentation (cherry picked from commit fb57759) Co-authored-by: Miguel Grinberg <[email protected]>
Iterators are expected to allow slicing twice, i.e.
This means essentially that
[a:a+b]
equals[a:][:b]
With a
Search
object slicing twice doesn't work:(Sorry for submitting an incomplete issue first, I accidentally hit the wrong key)
The text was updated successfully, but these errors were encountered: