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

Remove containing list around added and removed items in some list events #771

Merged
merged 1 commit into from Jan 20, 2020

Conversation

k2bd
Copy link
Contributor

@k2bd k2bd commented Jan 18, 2020

Closes #742

Updates the behaviour of list events when setting or deleting list objects via a slice with step size != 1.

Previously the added and deleted elements would be wrapped in an extra containing list:

self.obj.alist[0:4:2] = [10, 11]
self.assertLastTraitListEventEqual(
slice(0, 4, 2), [[8, 4]], [[10, 11]]
)
del self.obj.alist[1:4:2]
self.assertLastTraitListEventEqual(slice(1, 4, 2), [[9, 5]], [])

This PR removes this containing list to bring the behaviour more in line with that of other list actions.

Note there is still some bugwards-compatibility code in TraitListObject's __setitem__ and __delitem__ that is out-of-scope of this PR: the index of certain events is 0 in cases where the expectation would be a slice:

self.obj.alist[0:2] = [6, 7]
self.assertLastTraitListEventEqual(0, [2, 3], [6, 7])
self.obj.alist[:2] = [4, 5]
self.assertLastTraitListEventEqual(0, [6, 7], [4, 5])
self.obj.alist[0:2:1] = [8, 9]
self.assertLastTraitListEventEqual(0, [4, 5], [8, 9])

Opened #772 for that.

Comment on lines +208 to +218
def test_delete_step_slice_empty_list(self):
foo = MyClass()
foo.l = []

del foo.l[::-1]

self.assertEqual(len(foo.l_events), 1)
event, = foo.l_events
self.assertEqual(event.index, slice(None, None, -1))
self.assertEqual(event.removed, [])
self.assertEqual(event.added, [])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behaviour of this test would be changed by #740 as no list event would be fired

@codecov-io
Copy link

codecov-io commented Jan 18, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@6ac2718). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #771   +/-   ##
=========================================
  Coverage          ?   71.72%           
=========================================
  Files             ?       51           
  Lines             ?     6334           
  Branches          ?     1281           
=========================================
  Hits              ?     4543           
  Misses            ?     1393           
  Partials          ?      398
Impacted Files Coverage Δ
traits/trait_list_object.py 74.72% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6ac2718...6f404e2. Read the comment docs.

Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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 this pull request may close these issues.

TraitListObject misformats items_changed events on delete with extended slice
3 participants