|
19 | 19 | from os.path import isfile, isdir |
20 | 20 | import re |
21 | 21 | import sys |
22 | | -from types import FunctionType, MethodType, ModuleType |
| 22 | +from types import ModuleType |
23 | 23 | import uuid |
24 | 24 | import warnings |
25 | 25 |
|
|
35 | 35 | SequenceTypes, |
36 | 36 | TypeTypes, |
37 | 37 | Undefined, |
38 | | - TraitsCache, |
39 | 38 | xgetattr, |
40 | 39 | ) |
41 | 40 | from .trait_converters import trait_from, trait_cast |
|
51 | 50 | Trait, |
52 | 51 | _TraitMaker, |
53 | 52 | ) |
54 | | -from .util.deprecated import deprecated |
55 | | -from .util.import_symbol import import_symbol |
56 | 53 |
|
57 | 54 | # TraitsUI integration imports |
58 | 55 | from .editor_factories import ( |
@@ -980,64 +977,6 @@ class self(This): |
980 | 977 | default_value_type = DefaultValue.object |
981 | 978 |
|
982 | 979 |
|
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 | | - |
1041 | 980 | class Module(TraitType): |
1042 | 981 | """ A trait type whose value must be a module. |
1043 | 982 | """ |
@@ -4271,79 +4210,6 @@ def get_editor(self, trait): |
4271 | 4210 | return CompoundEditor(editors=editors) |
4272 | 4211 |
|
4273 | 4212 |
|
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 | | - |
4347 | 4213 | class UUID(TraitType): |
4348 | 4214 | """ A read-only trait type whose value is a globally unique UUID (type 4). |
4349 | 4215 |
|
|
0 commit comments