本文整理汇总了Python中traitlets.Undefined方法的典型用法代码示例。如果您正苦于以下问题:Python traitlets.Undefined方法的具体用法?Python traitlets.Undefined怎么用?Python traitlets.Undefined使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类traitlets
的用法示例。
在下文中一共展示了traitlets.Undefined方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __getattribute__
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import Undefined [as 别名]
def __getattribute__(self, name):
# Intercept everything and delegate to the device class by converting
# names between the D-Bus conventions to Python conventions.
prop_name = camel_to_snake(name)
if prop_name != name and self._delegate.has_trait(prop_name):
value = getattr(self._delegate, prop_name)
trait = self._delegate.traits()[prop_name]
if isinstance(trait, UseEnum):
return value.name.title()
if isinstance(trait, ColorSchemeTrait):
return [x.html for x in value]
if isinstance(trait, ColorTrait):
if value is None or value is Undefined:
return ''
return value.html
if isinstance(trait, tuple) and hasattr(trait, '_asdict'):
return trait._asdict()
return value
return super(TraitsPropertiesMixin, self).__getattribute__(name)
示例2: add_directive_header
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import Undefined [as 别名]
def add_directive_header(self, sig):
default = self.object.get_default_value()
if default is Undefined:
default_s = ''
else:
default_s = repr(default)
sig = ' = {}({})'.format(
self.object.__class__.__name__,
default_s,
)
return super().add_directive_header(sig)
示例3: test_initial_values
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import Undefined [as 别名]
def test_initial_values(self):
class Foo(HasTraits):
a = Array()
b = Array(dtype='int')
c = Array(None, allow_none=True)
d = Array([])
e = Array(Undefined)
foo = Foo()
self.assertTrue(np.array_equal(foo.a, np.array(0)))
self.assertTrue(np.array_equal(foo.b, np.array(0)))
self.assertTrue(foo.c is None)
self.assertTrue(np.array_equal(foo.d, []))
self.assertTrue(foo.e is Undefined)
示例4: __init__
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import Undefined [as 别名]
def __init__(self, default_value=Empty, allow_none=False, dtype=None, **kwargs):
self.dtype = dtype
if default_value is Empty:
default_value = np.array(0, dtype=self.dtype)
elif default_value is not None and default_value is not Undefined:
default_value = np.asarray(default_value, dtype=self.dtype)
super(Array, self).__init__(default_value=default_value, allow_none=allow_none, **kwargs)
示例5: make_dynamic_default
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import Undefined [as 别名]
def make_dynamic_default(self):
if self.default_value is None or self.default_value is Undefined:
return self.default_value
else:
return np.copy(self.default_value)
示例6: validate
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import Undefined [as 别名]
def validate(self, obj, value):
if value is None and not self.allow_none:
self.error(obj, value)
if value is None or value is Undefined:
return super(PandasType, self).validate(obj, value)
try:
value = self.klass(value)
except (ValueError, TypeError) as e:
raise TraitError(e)
return super(PandasType, self).validate(obj, value)
示例7: set
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import Undefined [as 别名]
def set(self, obj, value):
new_value = self._validate(obj, value)
old_value = obj._trait_values.get(self.name, self.default_value)
obj._trait_values[self.name] = new_value
if ((old_value is None and new_value is not None) or
(old_value is Undefined and new_value is not Undefined) or
not old_value.equals(new_value)):
obj._notify_trait(self.name, old_value, new_value)
示例8: add_directive_header
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import Undefined [as 别名]
def add_directive_header(self, sig):
default = self.object.default_value
if default is Undefined:
default = ""
# Ensures escape sequences render properly
default_s = repr(repr(default))[1:-1]
val = "= {}({})".format(self.object.__class__.__name__, default_s)
self.options.annotation = val
self.modname = ""
return super().add_directive_header(sig)