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

TraitListObject gives bad index for __setitem__ #994

Closed
mdickinson opened this issue Apr 8, 2020 · 2 comments · Fixed by #999
Closed

TraitListObject gives bad index for __setitem__ #994

mdickinson opened this issue Apr 8, 2020 · 2 comments · Fixed by #999
Assignees
Milestone

Comments

@mdickinson
Copy link
Member

Given the following code:

>>> from traits.api import *
>>> class A(HasTraits):
...     foo = List(Int)
...     def _foo_items_changed(self, event):
...         print(f"Index: {event.index}; Added: {event.added}; Removed: {event.removed}")
... 
>>> a = A()
>>> a.foo = list(range(10))
>>> a.foo
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

An assignment to a.foo[5:2] inserts new items at position 5. But the emitted TraitListEvent has an index of 2.

>>> a.foo[5:2] = [99]
Index: 2; Added: [99]; Removed: []
>>> a.foo
[0, 1, 2, 3, 4, 99, 5, 6, 7, 8, 9]
@mdickinson mdickinson added this to the 6.1.0 release milestone Apr 8, 2020
@mdickinson
Copy link
Member Author

It's conceivable that this is deliberate bug-for-bug compatibility with existing code. But I don't think so: there's no existing test that fails when I fix this, and it's hard to imagine how the current behaviour could be useful to anyone.

@mdickinson
Copy link
Member Author

Not deliberate: this is a regression from Traits 6.0.0. It needs a fix and a test.

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

Successfully merging a pull request may close this issue.

1 participant