Skip to content

Commit

Permalink
Remove deprecated TraitList, TraitDict and TraitTuple classes (#1634)
Browse files Browse the repository at this point in the history
This PR removes the TraitList, TraitDict and TraitTuple subclasses of TraitHandler, which have been deprecated since Traits 6.0. Users should use the List, Dict and Tuple subclasses of TraitType instead.
  • Loading branch information
mdickinson committed Apr 20, 2022
1 parent 99d0aa7 commit d056140
Show file tree
Hide file tree
Showing 9 changed files with 3 additions and 509 deletions.
10 changes: 1 addition & 9 deletions docs/source/traits_api_reference/trait_handlers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,11 @@ Private Functions
Deprecated Handlers
-------------------

.. deprecated:: 6.0.0
.. deprecated:: 6.1.0

The following :class:`~.TraitHandler` classes and instances are deprecated,
and may be removed in a future version of Traits.

.. autoclass:: TraitDict

.. autoclass:: TraitList

.. autoclass:: TraitTuple

.. deprecated:: 6.1.0

.. autoclass:: TraitPrefixList

.. autoclass:: TraitPrefixMap
3 changes: 1 addition & 2 deletions docs/source/traits_user_manual/internals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ Traits has the ability to watch for changes in standard Python containers:
lists, dictionaries and sets. To achieve this Traits provides special
subclasses of the standard Python classes that can validate elements and can
fire trait notifications when the contents change. These classes are,
respectively, |TraitList|, |TraitDict| and |TraitSet| (not to be confused with
the deprecated Trait Handlers of the same names).
respectively, |TraitList|, |TraitDict| and |TraitSet|.

In addition to being able to take an appropriate value to initialize the
container (such as a sequence or mapping), these container subclasses also
Expand Down
3 changes: 0 additions & 3 deletions traits-stubs/traits-stubs/api.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,4 @@ from .trait_handlers import (
TraitMap as TraitMap,
TraitPrefixMap as TraitPrefixMap,
TraitCompound as TraitCompound,
TraitList as TraitList,
TraitDict as TraitDict,
TraitTuple as TraitTuple,
)
25 changes: 0 additions & 25 deletions traits-stubs/traits-stubs/trait_handlers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,3 @@ class TraitCompound(TraitHandler):
def __init__(self,
*handlers: _Any) -> None:
...


class TraitTuple(TraitHandler):
def __init__(self,
*args: _Any) -> None:
...


class TraitList(TraitHandler):
def __init__(self,
trait: _Any = ...,
minlen: int = ...,
maxlen: int = ...,
has_items: bool = ...,
) -> None:
...


class TraitDict(TraitHandler):
def __init__(self,
key_trait: _Any = ...,
value_trait: _Any = ...,
has_items: bool = ...,
) -> None:
...
15 changes: 0 additions & 15 deletions traits-stubs/traits_stubs_tests/examples/TraitDict.py

This file was deleted.

3 changes: 0 additions & 3 deletions traits/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,6 @@
TraitMap,
TraitPrefixMap,
TraitCompound,
TraitList,
TraitDict,
TraitTuple,
)


Expand Down
6 changes: 0 additions & 6 deletions traits/tests/test_deprecated_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,15 @@
import warnings

from traits.api import (
TraitDict,
TraitList,
TraitPrefixList,
TraitPrefixMap,
TraitTuple,
)


class TestTraitHandlerDeprecatedWarnings(unittest.TestCase):

def test_handler_warning(self):
handlers = {
"TraitDict": TraitDict,
"TraitList": TraitList,
"TraitTuple": TraitTuple,
"TraitPrefixList": lambda: TraitPrefixList("one", "two"),
"TraitPrefixMap": lambda: TraitPrefixMap({}),
}
Expand Down
119 changes: 0 additions & 119 deletions traits/tests/test_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
This,
Trait,
TraitError,
TraitList,
TraitPrefixList,
TraitPrefixMap,
Tuple,
Expand Down Expand Up @@ -1066,124 +1065,6 @@ def test_enum_exceptions(self):
)


class test_list_value(test_base2):
def setUp(self):
with self.assertWarns(DeprecationWarning):

class list_value(HasTraits):
# Trait definitions:
list1 = Trait([2], TraitList(Trait([1, 2, 3, 4]), maxlen=4))
list2 = Trait(
[2], TraitList(Trait([1, 2, 3, 4]), minlen=1, maxlen=4)
)
alist = List()

self.obj = list_value()
self.last_event = None

def tearDown(self):
del self.last_event

def del_range(self, list, index1, index2):
del list[index1:index2]

def del_extended_slice(self, list, index1, index2, step):
del list[index1:index2:step]

def check_list(self, list):
self.assertEqual(list, [2])
self.assertEqual(len(list), 1)
list.append(3)
self.assertEqual(len(list), 2)
list[1] = 2
self.assertEqual(list[1], 2)
self.assertEqual(len(list), 2)
list[0] = 1
self.assertEqual(list[0], 1)
self.assertEqual(len(list), 2)
self.assertRaises(TraitError, self.indexed_assign, list, 0, 5)
self.assertRaises(TraitError, list.append, 5)
self.assertRaises(TraitError, list.extend, [1, 2, 3])
list.extend([3, 4])
self.assertEqual(list, [1, 2, 3, 4])
self.assertRaises(TraitError, list.append, 1)
self.assertRaises(
ValueError, self.extended_slice_assign, list, 0, 4, 2, [4, 5, 6]
)
del list[1]
self.assertEqual(list, [1, 3, 4])
del list[0]
self.assertEqual(list, [3, 4])
list[:0] = [1, 2]
self.assertEqual(list, [1, 2, 3, 4])
self.assertRaises(
TraitError, self.indexed_range_assign, list, 0, 0, [1]
)
del list[0:3]
self.assertEqual(list, [4])
self.assertRaises(
TraitError, self.indexed_range_assign, list, 0, 0, [4, 5]
)

def test_list1(self):
self.check_list(self.obj.list1)

def test_list2(self):
self.check_list(self.obj.list2)
self.assertRaises(TraitError, self.del_range, self.obj.list2, 0, 1)
self.assertRaises(
TraitError, self.del_extended_slice, self.obj.list2, 4, -5, -1
)

def assertLastTraitListEventEqual(self, index, removed, added):
self.assertEqual(self.last_event.index, index)
self.assertEqual(self.last_event.removed, removed)
self.assertEqual(self.last_event.added, added)

def test_trait_list_event(self):
""" Record TraitListEvent behavior.
"""
self.obj.alist = [1, 2, 3, 4]
self.obj.on_trait_change(self._record_trait_list_event, "alist_items")
del self.obj.alist[0]
self.assertLastTraitListEventEqual(0, [1], [])
self.obj.alist.append(5)
self.assertLastTraitListEventEqual(3, [], [5])
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])
self.obj.alist[0:2:1] = [8, 9]
# If list values stay the same, a new TraitListEvent will be generated.
self.assertLastTraitListEventEqual(0, [8, 9], [8, 9])
old_event = self.last_event
self.obj.alist[4:] = []
# If no structural change, NO new TraitListEvent will be generated.
self.assertIs(self.last_event, old_event)
self.obj.alist[0:4:2] = [10, 11]
self.assertLastTraitListEventEqual(
slice(0, 3, 2), [8, 4], [10, 11]
)
del self.obj.alist[1:4:2]
self.assertLastTraitListEventEqual(slice(1, 4, 2), [9, 5], [])
self.obj.alist = [1, 2, 3, 4]
del self.obj.alist[2:4]
self.assertLastTraitListEventEqual(2, [3, 4], [])
self.obj.alist[:0] = [5, 6, 7, 8]
self.assertLastTraitListEventEqual(0, [], [5, 6, 7, 8])
del self.obj.alist[:2]
self.assertLastTraitListEventEqual(0, [5, 6], [])
del self.obj.alist[0:2]
self.assertLastTraitListEventEqual(0, [7, 8], [])
del self.obj.alist[:]
self.assertLastTraitListEventEqual(0, [1, 2], [])

def _record_trait_list_event(self, object, name, old, new):
self.last_event = new


class ThisDummy(HasTraits):
allows_none = This()
disallows_none = This(allow_none=False)
Expand Down

0 comments on commit d056140

Please sign in to comment.