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
do 'the right thing' if a list, tuple, listish, range/xrange is passed in. #3
Comments
PyPy range objects internally behave like list-ishes |
I suspect the trick is to try and pass-through index lookups when not passed a generator? |
Yep python3 ranges are list-ish too. Lookups should be done that way you're right. Additionally I think there's an open question on whether modifying |
mutability wrapping could easily a whole new library, eg what if the items in the list are mutated? |
interesting stuff in https://docs.python.org/2/library/itertools.html#itertools.tee |
mutability wrapping is kind of half the point of listish (otherwise we'd just have made >>> l = [0, 1, 2, 3, 4, 5]
>>> listish = Listish(l)
>>> listish[3]
3
>>> l[1] = 'b'
>>> listish[1] != l[1]
True
>>> # and worse
>>> l.insert(3, 'd')
>>> list(iter(listish))
[0, 1, 2, 3, 3, 4, 5]
>>> l
[0, 'b', 2, 'd', 3, 4, 5] We can't control what people might do to the list after passing it to I think based on that it makes sense to ignore whether the input is mutable or not and treat it as if it isn't. >>> repr(Listish((,), passthrough_mutables=True))
Listish
>>> repr(Listish(someiter, passthrough_mutables=True))
Listish
>>> repr(Listish([1, 2, 3, 4], passthrough_mutables=True))
[1, 2, 3, 4]
>>> repr(Listish([1, 2, 3, 4]))
Listish (obviously we could improve our reprs but that's a separate issue :) |
lists, tuples and listish already support indexing
range/xrange have varying magic behaviour depending on CPython 2, CPython 3 or PyPy
The text was updated successfully, but these errors were encountered: