Skip to content
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

OrderedSet.pop() with a non-default index breaks the contract #83

Open
rspeer opened this issue Jan 26, 2022 · 1 comment · May be fixed by #84
Open

OrderedSet.pop() with a non-default index breaks the contract #83

rspeer opened this issue Jan 26, 2022 · 1 comment · May be fixed by #84

Comments

@rspeer
Copy link
Owner

rspeer commented Jan 26, 2022

>>> from ordered_set import OrderedSet
>>> a = OrderedSet(["a", "b", "c"])
>>> a.index("b")
1
>>> a.pop(0)
'a'
>>> a.index("b")
1
>>> a[1]
'c'

This was revealed by looking into #79. pop() would need to rebuild the mapping in place, like discard() does. Its current behavior, which only works for index=-1, would be an optimization.

@robert-phe robert-phe linked a pull request May 31, 2022 that will close this issue
@aranega
Copy link

aranega commented Jun 20, 2022

Hi @rspeer,

Thanks a lot for your library, it's really really handy! Regarding this point, I implemented some patch in my project to deal with pop/insert and item assignation without slices.

https://github.com/pyecore/pyecore/blob/master/pyecore/ordered_set_patch.py

It's probably not perfect and a little bit naïve implementation, but perhaps it could help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants