Skip to content

Commit

Permalink
Remove the deprecated SingletonHasTraits class and related classes (#…
Browse files Browse the repository at this point in the history
…1794)

This PR removes the long-deprecated (and untested) `SingletonHasTraits`,
`SingletonHasStrictTraits` and `SingletonHasPrivateTraits` classes.

Closes #911
  • Loading branch information
mdickinson authored May 9, 2024
1 parent 49b886f commit c0e09a4
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 94 deletions.
13 changes: 0 additions & 13 deletions docs/source/traits_api_reference/has_traits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

3 changes: 0 additions & 3 deletions traits/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@
HasPrivateTraits,
HasRequiredTraits,
Interface,
SingletonHasTraits,
SingletonHasStrictTraits,
SingletonHasPrivateTraits,
MetaHasTraits,
Vetoable,
VetoableEvent,
Expand Down
3 changes: 0 additions & 3 deletions traits/api.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
42 changes: 0 additions & 42 deletions traits/has_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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.
"""
Expand Down
9 changes: 0 additions & 9 deletions traits/has_traits.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...

Expand Down
24 changes: 0 additions & 24 deletions traits/tests/test_has_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
HasTraits,
observe,
ObserverTraits,
SingletonHasTraits,
SingletonHasStrictTraits,
SingletonHasPrivateTraits,
)
from traits.ctrait import CTrait
from traits.observation.api import (
Expand Down Expand Up @@ -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})
Expand Down

0 comments on commit c0e09a4

Please sign in to comment.