Skip to content

Commit

Permalink
Merge a7477d1 into b5cf152
Browse files Browse the repository at this point in the history
  • Loading branch information
jvkersch committed Oct 24, 2018
2 parents b5cf152 + a7477d1 commit ac27912
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 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):
pattern = getattr( value, 'on_trait_change', None )
if pattern is not None:
listeners[ name ] = ( 'method', pattern )
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, property ):
class_traits[ name ] = generic_trait
Expand Down
27 changes: 26 additions & 1 deletion traits/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from ..trait_numeric import Array

from ..has_traits import HasTraits, Property, on_trait_change
from ..trait_types import Bool, DelegatesTo, Either, Instance, Int, List
from ..trait_types import (
Bool, Callable, DelegatesTo, Either, Instance, Int, List
)
from ..testing.unittest_tools import unittest


Expand Down Expand Up @@ -232,5 +234,28 @@ 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

# Given

def fun():
pass

class A(HasTraits):
f = Callable()

class B(A):
f = fun

# When
b = B()

# Then
self.assertIsNotNone(b.f)


if __name__ == '__main__':
unittest.main()

0 comments on commit ac27912

Please sign in to comment.