From 1b3e67ecd46908b133f838baf039bfb6f90f2bae Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Tue, 30 Oct 2018 07:36:46 +0000 Subject: [PATCH] Revert "FIX: Check function attributes upon class creation" --- traits/has_traits.py | 8 ++++---- traits/tests/test_regression.py | 30 +----------------------------- 2 files changed, 5 insertions(+), 33 deletions(-) diff --git a/traits/has_traits.py b/traits/has_traits.py index 0453d0fc79..54420156ba 100644 --- a/traits/has_traits.py +++ b/traits/has_traits.py @@ -547,10 +547,10 @@ def __init__ ( self, cls, class_name, bases, class_dict, is_category ): prefix_list.append( name ) prefix_traits[ name ] = value - elif (( isinstance( value, FunctionType ) or - is_cython_func_or_method(value) ) and - hasattr( value, 'on_trait_change' )): - listeners[ name ] = ( 'method', value.on_trait_change ) + elif isinstance( value, FunctionType ) or is_cython_func_or_method(value): + pattern = getattr( value, 'on_trait_change', None ) + if pattern is not None: + listeners[ name ] = ( 'method', pattern ) elif isinstance( value, property ): class_traits[ name ] = generic_trait diff --git a/traits/tests/test_regression.py b/traits/tests/test_regression.py index cd03ca6930..b110fb0d36 100644 --- a/traits/tests/test_regression.py +++ b/traits/tests/test_regression.py @@ -11,9 +11,7 @@ from ..trait_numeric import Array from ..has_traits import HasTraits, Property, on_trait_change -from ..trait_types import ( - Bool, Callable, DelegatesTo, Either, Instance, Int, List -) +from ..trait_types import Bool, DelegatesTo, Either, Instance, Int, List from ..testing.unittest_tools import unittest @@ -234,31 +232,5 @@ def test_on_trait_change_with_list_of_extended_names(self): self.assertTrue(model.changed) -class TestDerivedClassDefaults(unittest.TestCase): - - def test_function_default(self): - # Regression test for enthought/traits#411. Providing a pure Python - # default in a child class for a Callable trait declared in the base - # class didn't work as expected -- the default value would be silently - # ignored. - - # Given - - def square(x): - return x ** 2 - - class A(HasTraits): - f = Callable() - - class B(A): - f = square - - # When - b = B() - - # Then - self.assertEquals(b.f(3), 9) - - if __name__ == '__main__': unittest.main()