Repository: enthought/traits (language: python)

Issue:
Remove SingletonHasTraits and related classes
The classes `SingletonHasTraits`, `SingletonHasStrictTraits` and `SingletonHasPrivateTraits` were deprecated in Traits 6.1.0. They should be removed in Traits 7.0.0.



Discussion / hints:

Fix patch:
diff --git a/docs/source/traits_api_reference/has_traits.rst b/docs/source/traits_api_reference/has_traits.rst
index 1bb3e9638..6359d0a82 100644
--- a/docs/source/traits_api_reference/has_traits.rst
+++ b/docs/source/traits_api_reference/has_traits.rst
@@ -68,16 +68,3 @@ Functions
 .. autofunction:: provides
 
 .. autofunction:: weak_arg
-
-Deprecated Classes
-------------------
-
-The following :class:`~.HasTraits` subclasses are deprecated,
-and may be removed in a future version of Traits.
-
-.. autoclass:: SingletonHasTraits
-
-.. autoclass:: SingletonHasStrictTraits
-
-.. autoclass:: SingletonHasPrivateTraits
-
diff --git a/traits/api.py b/traits/api.py
index 5da7d6111..d6ddf2288 100644
--- a/traits/api.py
+++ b/traits/api.py
@@ -146,9 +146,6 @@
     HasPrivateTraits,
     HasRequiredTraits,
     Interface,
-    SingletonHasTraits,
-    SingletonHasStrictTraits,
-    SingletonHasPrivateTraits,
     MetaHasTraits,
     Vetoable,
     VetoableEvent,
diff --git a/traits/api.pyi b/traits/api.pyi
index 473a7571e..10d043e38 100644
--- a/traits/api.pyi
+++ b/traits/api.pyi
@@ -42,9 +42,6 @@ from .has_traits import (
     HasPrivateTraits as HasPrivateTraits,
     HasRequiredTraits as HasRequiredTraits,
     Interface as Interface,
-    SingletonHasTraits as SingletonHasTraits,
-    SingletonHasStrictTraits as SingletonHasStrictTraits,
-    SingletonHasPrivateTraits as SingletonHasPrivateTraits,
     MetaHasTraits as MetaHasTraits,
     Vetoable as Vetoable,
     VetoableEvent as VetoableEvent,
diff --git a/traits/has_traits.py b/traits/has_traits.py
index 58d056a84..5ccac2010 100644
--- a/traits/has_traits.py
+++ b/traits/has_traits.py
@@ -54,7 +54,6 @@
     not_false,
 )
 from .trait_errors import TraitError
-from .util.deprecated import deprecated
 from .trait_converters import check_trait, mapped_trait_for, trait_for
 
 
@@ -3557,47 +3556,6 @@ class ABCHasStrictTraits(ABCHasTraits):
     _ = Disallow
 
 
-#  Singleton classes with traits:
-#
-#  This code is based on a recipe taken from:
-#      http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531
-#  Specifically, the implementation of Oren Tirosh is used.
-
-class SingletonHasTraits(HasTraits):
-    """ Singleton class that support trait attributes.
-    """
-
-    @deprecated("SingletonHasTraits has been deprecated and will be removed "
-                "in the future. Avoid using it")
-    def __new__(cls, *args, **traits):
-        if "_the_instance" not in cls.__dict__:
-            cls._the_instance = HasTraits.__new__(cls, *args, **traits)
-        return cls._the_instance
-
-
-class SingletonHasStrictTraits(HasStrictTraits):
-    """ Singleton class that supports strict trait attributes.
-
-        Non-trait attributes generate an exception.
-    """
-
-    @deprecated("SingletonHasStrictTraits has been deprecated and will be "
-                "removed in the future. Avoid using it")
-    def __new__(cls, *args, **traits):
-        return SingletonHasTraits.__new__(cls, *args, **traits)
-
-
-class SingletonHasPrivateTraits(HasPrivateTraits):
-    """ Singleton class that supports trait attributes, with private attributes
-        being unchecked.
-    """
-
-    @deprecated("SingletonHasPrivateTraits has been deprecated and will be "
-                "removed in the future. Avoid using it")
-    def __new__(cls, *args, **traits):
-        return SingletonHasTraits.__new__(cls, *args, **traits)
-
-
 class Vetoable(HasStrictTraits):
     """ Defines a 'vetoable' request object and an associated event.
     """
diff --git a/traits/has_traits.pyi b/traits/has_traits.pyi
index 899a711d7..819e55b27 100644
--- a/traits/has_traits.pyi
+++ b/traits/has_traits.pyi
@@ -132,15 +132,6 @@ class ABCMetaHasTraits(abc.ABCMeta, MetaHasTraits): ...
 class ABCHasTraits(HasTraits, metaclass=ABCMetaHasTraits): ...
 class ABCHasStrictTraits(ABCHasTraits): ...
 
-class SingletonHasTraits(HasTraits):
-    def __new__(cls, *args: _Any, **traits: _Any): ...
-
-class SingletonHasStrictTraits(HasStrictTraits):
-    def __new__(cls, *args: _Any, **traits: _Any): ...
-
-class SingletonHasPrivateTraits(HasPrivateTraits):
-    def __new__(cls, *args: _Any, **traits: _Any): ...
-
 class Vetoable(HasStrictTraits):
     veto: _Any = ...
 


Test patch:
diff --git a/traits/tests/test_has_traits.py b/traits/tests/test_has_traits.py
index 9a2d0856f..c9fa860b7 100644
--- a/traits/tests/test_has_traits.py
+++ b/traits/tests/test_has_traits.py
@@ -23,9 +23,6 @@
     HasTraits,
     observe,
     ObserverTraits,
-    SingletonHasTraits,
-    SingletonHasStrictTraits,
-    SingletonHasPrivateTraits,
 )
 from traits.ctrait import CTrait
 from traits.observation.api import (
@@ -760,27 +757,6 @@ def _x_changed(self):
         self.assertEqual(side_effects, ["object1", "object2"])
 
 
-class TestDeprecatedHasTraits(unittest.TestCase):
-    def test_deprecated(self):
-        class TestSingletonHasTraits(SingletonHasTraits):
-            pass
-
-        class TestSingletonHasStrictTraits(SingletonHasStrictTraits):
-            pass
-
-        class TestSingletonHasPrivateTraits(SingletonHasPrivateTraits):
-            pass
-
-        with self.assertWarns(DeprecationWarning):
-            TestSingletonHasTraits()
-
-        with self.assertWarns(DeprecationWarning):
-            TestSingletonHasStrictTraits()
-
-        with self.assertWarns(DeprecationWarning):
-            TestSingletonHasPrivateTraits()
-
-
 class MappedWithDefault(HasTraits):
 
     married = Map({"yes": 1, "yeah": 1, "no": 0, "nah": 0})