本文整理匯總了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)