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

Make TraitListObject notify even if list values stay the same #1026

Merged
merged 4 commits into from
Apr 24, 2020

Conversation

ievacerny
Copy link
Contributor

@ievacerny ievacerny commented Apr 23, 2020

Closes #972

This PR changes the behaviour of TraitListObject. From now on it will notify even if the underlying list doesn't change (it didn't before). An exception - notification is still suppressed if there is no structural change.

For example, given a class:

>>> class Foo(HasTraits):
...     bar = List([1, 2, 3])
...     @on_trait_change('bar[]')
...     def report_bar_change(self, obj, name, old, new):
...         print(f"Some bar values changed: {old} --> {new}")
...
>>> f = Foo()

all of the following will notify listeners:

>>> f.bar[0] = 1
Some bar values changed: [1] --> [1]
>>> f.bar[:2] = [1, 2]
Some bar values changed: [1, 2] --> [1, 2]

The exception - no structural change:

>>> f.bar[3:] = []
>>>

Checklist

  • Tests
  • [ ] Update API reference (docs/source/traits_api_reference)
  • [ ] Update User manual (docs/source/traits_user_manual)
  • [ ] Update type annotation hints in traits-stubs

@codecov-io
Copy link

codecov-io commented Apr 24, 2020

Codecov Report

Merging #1026 into master will increase coverage by 2.67%.
The diff coverage is 97.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1026      +/-   ##
==========================================
+ Coverage   73.05%   75.73%   +2.67%     
==========================================
  Files          51       54       +3     
  Lines        6514     6511       -3     
  Branches     1309     1280      -29     
==========================================
+ Hits         4759     4931     +172     
+ Misses       1363     1227     -136     
+ Partials      392      353      -39     
Impacted Files Coverage Δ
traits/api.py 90.32% <ø> (ø)
traits/trait_base.py 68.83% <ø> (+5.25%) ⬆️
traits/trait_dict_object.py 75.44% <ø> (ø)
traits/trait_set_object.py 95.42% <ø> (+29.20%) ⬆️
traits/trait_types.py 72.45% <92.59%> (+0.81%) ⬆️
traits/trait_list_object.py 97.51% <97.69%> (+23.22%) ⬆️
traits/ctrait.py 71.07% <100.00%> (+12.51%) ⬆️
traits/has_traits.py 72.75% <100.00%> (+1.50%) ⬆️
traits/observers/_i_observer.py 100.00% <100.00%> (ø)
traits/observers/_named_trait_observer.py 100.00% <100.00%> (ø)
... and 17 more

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 046e68a...1dff3e2. 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

@ievacerny ievacerny merged commit 99d83bd into master Apr 24, 2020
@ievacerny ievacerny deleted the fix/traitlistobject-notification-list-unchanged branch April 24, 2020 13:58
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 does not notify if an operation keeps the list unchanged.
3 participants