From 5de5c08105d501adbacdd60e4b5c3f9ed5da8137 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 18 Aug 2022 15:26:33 +0100 Subject: [PATCH 1/2] Remove the deprecated adapt-by-calling ability of Interfaces --- traits/has_traits.py | 22 +++------------------ traits/tests/test_interface_checker.py | 27 +++++--------------------- 2 files changed, 8 insertions(+), 41 deletions(-) diff --git a/traits/has_traits.py b/traits/has_traits.py index e8e3222ec..507e69c7d 100644 --- a/traits/has_traits.py +++ b/traits/has_traits.py @@ -25,7 +25,6 @@ from types import FunctionType from . import __version__ as TraitsVersion -from .adaptation.adaptation_error import AdaptationError from .constants import DefaultValue, TraitKind from .ctrait import CTrait, __newobj__ from .ctraits import CHasTraits @@ -3679,26 +3678,11 @@ def _veto_changed(self, state): class MetaInterface(ABCMetaHasTraits): """ Meta class for interfaces. - Interfaces are simple ABCs with the following features:- - - 1) They cannot be instantiated (they are interfaces, not implementations!). - 2) Calling them is equivalent to calling 'adapt'. - + Historically, there were some differences between interfaces + and ABCs in Traits, but now Interface is a near synonym for + ABCHasTraits. """ - @deprecated('use "adapt(adaptee, protocol)" instead.') - def __call__(self, adaptee, default=AdaptationError): - """ Attempt to adapt the adaptee to this interface. - - Note that this means that (intentionally ;^) that interfaces - cannot be instantiated! - - """ - - from traits.adaptation.api import adapt - - return adapt(adaptee, self, default=default) - class Interface(HasTraits, metaclass=MetaInterface): """ The base class for all interfaces. diff --git a/traits/tests/test_interface_checker.py b/traits/tests/test_interface_checker.py index d6e594ccd..dc857b9e5 100644 --- a/traits/tests/test_interface_checker.py +++ b/traits/tests/test_interface_checker.py @@ -12,11 +12,11 @@ # Standard library imports. import unittest -import warnings # Enthought library imports. from traits.adaptation.api import reset_global_adaptation_manager from traits.api import ( + adapt, Adapter, HasTraits, Instance, @@ -388,15 +388,7 @@ class Foo(HasTraits): # Adaptation via direct instantiation of interfaces is deprecated, so # catch the warning to keep the test run output clean. - with warnings.catch_warnings(record=True) as warn_msgs: - warnings.simplefilter("always", DeprecationWarning) - self.assertEqual(f, IFoo(f)) - - self.assertEqual(len(warn_msgs), 1) - warn_msg = warn_msgs[0] - self.assertIn( - 'use "adapt(adaptee, protocol)" instead', str(warn_msg.message)) - self.assertIn("test_interface_checker", warn_msg.filename) + self.assertEqual(f, adapt(f, IFoo)) def test_adaptation(self): """ adaptation """ @@ -415,17 +407,8 @@ class FooToIFooAdapter(Adapter): f = Foo() - # Make sure adaptation works. Adaptation via direct instantiation of - # Interface classes is deprecated, so suppress the warning. - with warnings.catch_warnings(record=True) as warn_msgs: - warnings.simplefilter("always", DeprecationWarning) - i_foo = IFoo(f) + # Make sure adaptation works. + i_foo = adapt(f, IFoo) - self.assertNotEqual(None, i_foo) + self.assertIsNotNone(i_foo) self.assertEqual(FooToIFooAdapter, type(i_foo)) - - self.assertEqual(len(warn_msgs), 1) - warn_msg = warn_msgs[0] - self.assertIn( - 'use "adapt(adaptee, protocol)" instead', str(warn_msg.message)) - self.assertIn("test_interface_checker", warn_msg.filename) From 12d27d96ed80faa34342ff2f4b2150de0fd66632 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 18 Aug 2022 15:53:39 +0100 Subject: [PATCH 2/2] Remove outdated comment --- traits/tests/test_interface_checker.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/traits/tests/test_interface_checker.py b/traits/tests/test_interface_checker.py index dc857b9e5..6707b585c 100644 --- a/traits/tests/test_interface_checker.py +++ b/traits/tests/test_interface_checker.py @@ -386,8 +386,6 @@ class Foo(HasTraits): f = Foo() - # Adaptation via direct instantiation of interfaces is deprecated, so - # catch the warning to keep the test run output clean. self.assertEqual(f, adapt(f, IFoo)) def test_adaptation(self):