Skip to content

Commit

Permalink
Merge pull request #413 from enthought/revert-412-fix/gh-441
Browse files Browse the repository at this point in the history
Revert "FIX: Check function attributes upon class creation"
  • Loading branch information
mdickinson committed Oct 30, 2018
2 parents 7cd60f6 + 1b3e67e commit 77a6409
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 33 deletions.
8 changes: 4 additions & 4 deletions traits/has_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 1 addition & 29 deletions traits/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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()

0 comments on commit 77a6409

Please sign in to comment.