diff --git a/changelog.d/20240621_105210_mdickinson_add_event_types_to_api.rst b/changelog.d/20240621_105210_mdickinson_add_event_types_to_api.rst new file mode 100644 index 000000000..34f2f1cf2 --- /dev/null +++ b/changelog.d/20240621_105210_mdickinson_add_event_types_to_api.rst @@ -0,0 +1,36 @@ +.. A new scriv changelog fragment. +.. +.. Uncomment the header that is right (remove the leading dots). +.. +.. Removed +.. ------- +.. +.. - A bullet item for the Removed category. +.. +Added +----- + +- Event types for the ``event`` received by observers have been made + available in ``traits.observation.api``. This is useful for those + wanting to use the types in type annotations. (#1805) + +.. Changed +.. ------- +.. +.. - A bullet item for the Changed category. +.. +.. Deprecated +.. ---------- +.. +.. - A bullet item for the Deprecated category. +.. +.. Fixed +.. ----- +.. +.. - A bullet item for the Fixed category. +.. +.. Security +.. -------- +.. +.. - A bullet item for the Security category. +.. diff --git a/traits/observation/api.py b/traits/observation/api.py index 28e855df8..9101eec16 100644 --- a/traits/observation/api.py +++ b/traits/observation/api.py @@ -8,6 +8,13 @@ # # Thanks for using Enthought open source! +from traits.observation.events import ( + DictChangeEvent, + ListChangeEvent, + SetChangeEvent, + TraitChangeEvent, +) + from traits.observation.exception_handling import ( pop_exception_handler, push_exception_handler, diff --git a/traits/observation/tests/test_dict_change_event.py b/traits/observation/tests/test_dict_change_event.py index 6a23d5aa2..c342dd3a1 100644 --- a/traits/observation/tests/test_dict_change_event.py +++ b/traits/observation/tests/test_dict_change_event.py @@ -10,10 +10,8 @@ import unittest -from traits.observation._dict_change_event import ( - DictChangeEvent, - dict_event_factory, -) +from traits.observation.api import DictChangeEvent +from traits.observation._dict_change_event import dict_event_factory from traits.trait_dict_object import TraitDict diff --git a/traits/observation/tests/test_list_change_event.py b/traits/observation/tests/test_list_change_event.py index a5422bb3d..7f1a0ebee 100644 --- a/traits/observation/tests/test_list_change_event.py +++ b/traits/observation/tests/test_list_change_event.py @@ -10,10 +10,8 @@ import unittest -from traits.observation._list_change_event import ( - ListChangeEvent, - list_event_factory, -) +from traits.observation.api import ListChangeEvent +from traits.observation._list_change_event import list_event_factory from traits.trait_list_object import TraitList diff --git a/traits/observation/tests/test_set_change_event.py b/traits/observation/tests/test_set_change_event.py index 134e4b161..7554de003 100644 --- a/traits/observation/tests/test_set_change_event.py +++ b/traits/observation/tests/test_set_change_event.py @@ -10,10 +10,8 @@ import unittest -from traits.observation._set_change_event import ( - SetChangeEvent, - set_event_factory, -) +from traits.observation.api import SetChangeEvent +from traits.observation._set_change_event import set_event_factory from traits.trait_set_object import TraitSet diff --git a/traits/observation/tests/test_trait_change_event.py b/traits/observation/tests/test_trait_change_event.py index a39aa5ff1..d87e4e6ad 100644 --- a/traits/observation/tests/test_trait_change_event.py +++ b/traits/observation/tests/test_trait_change_event.py @@ -12,10 +12,8 @@ from traits.has_traits import HasTraits from traits.trait_types import Int -from traits.observation._trait_change_event import ( - trait_event_factory, - TraitChangeEvent, -) +from traits.observation.api import TraitChangeEvent +from traits.observation._trait_change_event import trait_event_factory class TestTraitChangeEvent(unittest.TestCase):