Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ Fixes
* `TraitSetObject.copy` now returns a plain rather than an
uninitialized `TraitSetObject` instance. (#97)
* Fix cyclic garbage arising from dynamic trait change handlers. (#101)
* Fix error when trying to listen to traits using list bracket notation (#195)
24 changes: 23 additions & 1 deletion traits/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

from ..has_traits import HasTraits, Property, on_trait_change
from ..trait_types import Bool, DelegatesTo, Instance, Int
from ..trait_types import Bool, DelegatesTo, Instance, Int, List
from ..testing.unittest_tools import unittest


Expand Down Expand Up @@ -55,6 +55,16 @@ def _get_y(self):
return self.obj.x


class ListUpdatesTest(HasTraits):
a = List
b = List
events_received = Int(0)

@on_trait_change('a[], b[]')
def _receive_events(self):
self.events_received += 1


class TestRegression(unittest.TestCase):

def test_default_value_for_no_cache(self):
Expand Down Expand Up @@ -106,5 +116,17 @@ def test_no_leaking_notifiers(self):
del presenter
self.assertEqual(len(ctrait._notifiers(1)), 0)

def test_init_list_depends(self):
""" Using two lists with bracket notation in extended name notation
should not raise an error.
"""
list_test = ListUpdatesTest()
# Updates to list items and the list trait itself should be counted.
list_test.a.append(0)
list_test.b = [1, 2, 3]
list_test.b[0] = 0
self.assertEqual(list_test.events_received, 3)


if __name__ == '__main__':
unittest.main()
5 changes: 4 additions & 1 deletion traits/traits_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,10 @@ def parse_item ( self, terminator ):
return result

if c == '[':
if (self.skip_ws == ']') and (self.skip_ws == terminator):
is_closing_bracket = (self.skip_ws == ']')
next_char = self.skip_ws
item_complete = (next_char == terminator or next_char == ',')
if is_closing_bracket and item_complete:
self.backspace
result.is_list_handler = True
else:
Expand Down