Skip to content

Commit

Permalink
Fix deprecation of Function and Method (#1543)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdickinson authored Sep 21, 2021
1 parent bc46f0f commit ffd6979
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions traits/tests/test_trait_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,21 @@ class MyTraitType(TraitType):

class TestDeprecatedTraitTypes(unittest.TestCase):
def test_function_deprecated(self):
def some_function():
pass

with self.assertWarnsRegex(DeprecationWarning, "Function trait type"):
Function()
with self.assertWarnsRegex(DeprecationWarning, "Function trait type"):
Function(some_function, washable=True)

def test_method_deprecated(self):

class A:
def some_method(self):
pass

with self.assertWarnsRegex(DeprecationWarning, "Method trait type"):
Method()
with self.assertWarnsRegex(DeprecationWarning, "Method trait type"):
Method(A().some_method, gluten_free=False)
8 changes: 4 additions & 4 deletions traits/trait_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,8 @@ class Function(TraitType):

@deprecated("Function trait type has been deprecated. Use 'Callable' or "
"'Instance(types.FunctionType)' instead")
def __init__(self):
super().__init__()
def __init__(self, default_value=NoDefaultSpecified, **metadata):
super().__init__(default_value=default_value, **metadata)

#: The C-level fast validator to use:
fast_validate = (ValidateTrait.coerce, FunctionType)
Expand Down Expand Up @@ -1039,8 +1039,8 @@ class Method(TraitType):

@deprecated("Method trait type has been deprecated. Use 'Callable' or "
"'Instance(types.MethodType)' instead")
def __init__(self):
super().__init__()
def __init__(self, default_value=NoDefaultSpecified, **metadata):
super().__init__(default_value=default_value, **metadata)

#: The C-level fast validator to use:
fast_validate = (ValidateTrait.coerce, MethodType)
Expand Down

0 comments on commit ffd6979

Please sign in to comment.