Skip to content

Commit 3e0c266

Browse files
authored
Remove deprecated trait types Function, Method, and Symbol (#1819)
This PR removes the long-deprecated trait types `Function`, `Method` and `Symbol`.
1 parent d08f6fb commit 3e0c266

File tree

8 files changed

+4
-207
lines changed

8 files changed

+4
-207
lines changed

docs/source/traits_api_reference/trait_types.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@ Traits
115115
.. autoclass:: self
116116
:show-inheritance:
117117

118-
.. autoclass:: Function
119-
:show-inheritance:
120-
121-
.. autoclass:: Method
122-
:show-inheritance:
123-
124118
.. autoclass:: Module
125119
:show-inheritance:
126120

@@ -244,9 +238,6 @@ Traits
244238
.. autoclass:: Either
245239
:show-inheritance:
246240

247-
.. autoclass:: Symbol
248-
:show-inheritance:
249-
250241
.. autoclass:: UUID
251242
:show-inheritance:
252243

docs/source/traits_user_manual/defining.rst

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ the table.
264264
.. index:: CSet(), Constant(), Date(), Datetime(), Dict()
265265
.. index:: Directory(), Disallow, Either(), Enum()
266266
.. index:: Event(), Expression(), false, File()
267-
.. index:: Instance(), List(), Method(), Module()
267+
.. index:: Instance(), List(), Module()
268268
.. index:: Password(), Property(), Python()
269269
.. index:: PythonValue(), Range(), ReadOnly(), Regex()
270270
.. index:: Set() String(), This, Time()
@@ -333,8 +333,6 @@ the table.
333333
| File | File([*value* = '', *filter* = None, *auto_set* = False, |
334334
| | *entries* = 10, *exists* = False, \*\*\ *metadata*]) |
335335
+------------------+----------------------------------------------------------+
336-
| Function [3]_ | Function([*value* = None, \*\*\ *metadata*]) |
337-
+------------------+----------------------------------------------------------+
338336
| generic_trait | n/a |
339337
+------------------+----------------------------------------------------------+
340338
| HTML | HTML([*value* = '', *minlen* = 0, |
@@ -351,8 +349,6 @@ the table.
351349
+------------------+----------------------------------------------------------+
352350
| Map | Map(*map*\ [, \*\*\ *metadata*]) |
353351
+------------------+----------------------------------------------------------+
354-
| Method [3]_ | Method([\*\*\ *metadata*]) |
355-
+------------------+----------------------------------------------------------+
356352
| Module | Module([\*\*\ *metadata*]) |
357353
+------------------+----------------------------------------------------------+
358354
| Password | Password([*value* = '', *minlen* = 0, *maxlen* = |
@@ -1055,16 +1051,8 @@ the metadata attribute::
10551051
.. [2] The :class:`~.Either` trait type is likely to be deprecated at some
10561052
point in the future. The :class:`~.Union` trait type should be preferred
10571053
to :class:`~.Either` in new code.
1058-
.. [3] The Function and Method trait types are now deprecated. See |Function|,
1059-
|Method|
10601054
10611055
..
10621056
external urls
10631057
10641058
.. _Traits bug tracker: https://github.com/enthought/traits/issues
1065-
1066-
..
1067-
# substitutions
1068-
1069-
.. |Function| replace:: :class:`~traits.trait_types.Function`
1070-
.. |Method| replace:: :class:`~traits.trait_types.Method`

traits/api.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@
7272
Callable,
7373
This,
7474
self,
75-
Function,
76-
Method,
7775
Module,
7876
Python,
7977
ReadOnly,
@@ -107,7 +105,6 @@
107105
Union,
108106
Type,
109107
Subclass,
110-
Symbol,
111108
WeakRef,
112109
Date,
113110
Datetime,

traits/api.pyi

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ from .trait_types import (
7676
Callable as Callable,
7777
This as This,
7878
self as self,
79-
Function as Function,
80-
Method as Method,
8179
Module as Module,
8280
Python as Python,
8381
ReadOnly as ReadOnly,
@@ -111,7 +109,6 @@ from .trait_types import (
111109
Union as Union,
112110
Type as Type,
113111
Subclass as Subclass,
114-
Symbol as Symbol,
115112
WeakRef as WeakRef,
116113
Date as Date,
117114
Datetime as Datetime,

traits/tests/test_trait_types.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
from traits.api import (
2323
DefaultValue,
2424
Float,
25-
Function,
26-
Method,
2725
NoDefaultSpecified,
28-
Symbol,
2926
TraitType,
3027
Undefined
3128
)
@@ -145,29 +142,3 @@ def __init__(self, default_value=NoDefaultSpecified, **metadata):
145142
self.assertEqual(ctrait.default_value_for(None, "dummy"), 81)
146143
cloned_ctrait = trait(30)
147144
self.assertEqual(cloned_ctrait.default_value_for(None, "dummy"), 30)
148-
149-
150-
class TestDeprecatedTraitTypes(unittest.TestCase):
151-
def test_function_deprecated(self):
152-
def some_function():
153-
pass
154-
155-
with self.assertWarnsRegex(DeprecationWarning, "Function trait type"):
156-
Function()
157-
with self.assertWarnsRegex(DeprecationWarning, "Function trait type"):
158-
Function(some_function, washable=True)
159-
160-
def test_method_deprecated(self):
161-
162-
class A:
163-
def some_method(self):
164-
pass
165-
166-
with self.assertWarnsRegex(DeprecationWarning, "Method trait type"):
167-
Method()
168-
with self.assertWarnsRegex(DeprecationWarning, "Method trait type"):
169-
Method(A().some_method, gluten_free=False)
170-
171-
def test_symbol_deprecated(self):
172-
with self.assertWarnsRegex(DeprecationWarning, "Symbol trait type"):
173-
Symbol("random:random")

traits/trait_handlers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,8 @@ class TraitFunction(TraitHandler):
408408
"""Ensures that assigned trait attribute values are acceptable to a
409409
specified validator function.
410410
411-
TraitFunction is the underlying handler for the predefined trait
412-
**Function**, and for the use of function references as arguments to the
413-
Trait() function.
411+
TraitFunction is the underlying handler for the use of function references
412+
as arguments to the Trait() function.
414413
415414
The signature of the function must be of the form *function*(*object*,
416415
*name*, *value*). The function must verify that *value* is a legal value

traits/trait_types.py

Lines changed: 1 addition & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from os.path import isfile, isdir
2020
import re
2121
import sys
22-
from types import FunctionType, MethodType, ModuleType
22+
from types import ModuleType
2323
import uuid
2424
import warnings
2525

@@ -35,7 +35,6 @@
3535
SequenceTypes,
3636
TypeTypes,
3737
Undefined,
38-
TraitsCache,
3938
xgetattr,
4039
)
4140
from .trait_converters import trait_from, trait_cast
@@ -51,8 +50,6 @@
5150
Trait,
5251
_TraitMaker,
5352
)
54-
from .util.deprecated import deprecated
55-
from .util.import_symbol import import_symbol
5653

5754
# TraitsUI integration imports
5855
from .editor_factories import (
@@ -980,64 +977,6 @@ class self(This):
980977
default_value_type = DefaultValue.object
981978

982979

983-
class Function(TraitType):
984-
""" A trait type whose value must be a function.
985-
986-
.. deprecated:: 6.2.0
987-
This trait type explicitly checks for an instance of
988-
``types.FunctionType``. For the majority of use cases, the more general
989-
``Callable`` trait type should be used instead. If an instance
990-
specifically of ``types.FunctionType`` really is needed, one can use
991-
``Instance(types.FunctionType)``.
992-
"""
993-
994-
#: The default value type to use.
995-
default_value_type = DefaultValue.constant
996-
997-
#: The default value for the trait type.
998-
default_value = Undefined
999-
1000-
@deprecated("Function trait type has been deprecated. Use 'Callable' or "
1001-
"'Instance(types.FunctionType)' instead")
1002-
def __init__(self, default_value=NoDefaultSpecified, **metadata):
1003-
super().__init__(default_value=default_value, **metadata)
1004-
1005-
#: The C-level fast validator to use:
1006-
fast_validate = (ValidateTrait.coerce, FunctionType)
1007-
1008-
#: A description of the type of value this trait accepts:
1009-
info_text = "a function"
1010-
1011-
1012-
class Method(TraitType):
1013-
""" A trait type whose value must be a method.
1014-
1015-
.. deprecated:: 6.2.0
1016-
This trait type explicitly checks for an instance of
1017-
``types.MethodType``. For the majority of use cases, the more general
1018-
``Callable`` trait type should be used instead. If an instance
1019-
specifically of ``types.MethodType`` really is needed, one can use
1020-
``Instance(types.MethodType)``.
1021-
"""
1022-
1023-
#: The default value type to use.
1024-
default_value_type = DefaultValue.constant
1025-
1026-
#: The default value for the trait type.
1027-
default_value = Undefined
1028-
1029-
@deprecated("Method trait type has been deprecated. Use 'Callable' or "
1030-
"'Instance(types.MethodType)' instead")
1031-
def __init__(self, default_value=NoDefaultSpecified, **metadata):
1032-
super().__init__(default_value=default_value, **metadata)
1033-
1034-
#: The C-level fast validator to use:
1035-
fast_validate = (ValidateTrait.coerce, MethodType)
1036-
1037-
#: A description of the type of value this trait accepts:
1038-
info_text = "a method"
1039-
1040-
1041980
class Module(TraitType):
1042981
""" A trait type whose value must be a module.
1043982
"""
@@ -4271,79 +4210,6 @@ def get_editor(self, trait):
42714210
return CompoundEditor(editors=editors)
42724211

42734212

4274-
# -------------------------------------------------------------------------------
4275-
# 'Symbol' trait:
4276-
# -------------------------------------------------------------------------------
4277-
class Symbol(TraitType):
4278-
""" A property trait type that refers to a Python object by name.
4279-
4280-
The value set to the trait must be a value of the form
4281-
``'[package.package...package.]module[:symbol[([arg1,...,argn])]]'``
4282-
which is imported and evaluated to get underlying value.
4283-
4284-
The value returned by the trait is the actual object that this string
4285-
refers to. The value is cached, so any calls are only evaluated once.
4286-
4287-
.. deprecated:: 6.3.0
4288-
This trait type is deprecated, and will be removed in a future
4289-
version of Traits.
4290-
"""
4291-
4292-
@deprecated("The Symbol trait type has been deprecated.")
4293-
def __init__(self, default_value=NoDefaultSpecified, **metadata):
4294-
super().__init__(default_value=default_value, **metadata)
4295-
4296-
#: A description of the type of value this trait accepts:
4297-
info_text = (
4298-
"an object or a string of the form "
4299-
"'[package.package...package.]module[:symbol[([arg1,...,argn])]]' "
4300-
"specifying where to locate the object"
4301-
)
4302-
4303-
def get(self, object, name):
4304-
value = object.__dict__.get(name, Undefined)
4305-
if value is Undefined:
4306-
cache = TraitsCache + name
4307-
ref = object.__dict__.get(cache)
4308-
if ref is None:
4309-
object.__dict__[cache] = ref = object.trait(
4310-
name
4311-
).default_value_for(object, name)
4312-
4313-
if isinstance(ref, str):
4314-
object.__dict__[name] = value = self._resolve(ref)
4315-
4316-
return value
4317-
4318-
def set(self, object, name, value):
4319-
dict = object.__dict__
4320-
old = dict.get(name, Undefined)
4321-
if isinstance(value, str):
4322-
dict.pop(name, None)
4323-
dict[TraitsCache + name] = value
4324-
object.trait_property_changed(name, old)
4325-
else:
4326-
dict[name] = value
4327-
object.trait_property_changed(name, old, value)
4328-
4329-
def _resolve(self, ref):
4330-
try:
4331-
elements = ref.split("(", 1)
4332-
symbol = import_symbol(elements[0])
4333-
if len(elements) == 1:
4334-
return symbol
4335-
4336-
args = eval("(" + elements[1])
4337-
if not isinstance(args, tuple):
4338-
args = (args,)
4339-
4340-
return symbol(*args)
4341-
except Exception:
4342-
raise TraitError(
4343-
"Could not resolve '%s' into a valid symbol." % ref
4344-
)
4345-
4346-
43474213
class UUID(TraitType):
43484214
""" A read-only trait type whose value is a globally unique UUID (type 4).
43494215

traits/trait_types.pyi

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,6 @@ class self(This):
250250
...
251251

252252

253-
class Function(_TraitType[_OptionalCallable, _OptionalCallable]):
254-
...
255-
256-
257-
class Method(_TraitType[_OptionalCallable, _OptionalCallable]):
258-
...
259-
260-
261253
class Module(_TraitType[_Any, _Any]):
262254
...
263255

@@ -597,10 +589,6 @@ class Union(_TraitType[_Any, _Any]):
597589
...
598590

599591

600-
class Symbol(_TraitType[_Any, _Any]):
601-
...
602-
603-
604592
class UUID(_TraitType[_Union[str, _UUID], _UUID]):
605593
def __init__(
606594
self,

0 commit comments

Comments
 (0)