我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用traitlets.Bool()。
def __eq__(self, other)->Bool: """ Equality and hash do not hash the type (as some completer may not be able to infer the type), but are use to (partially) de-duplicate completion. Completely de-duplicating completion is a bit tricker that just comparing as it depends on surrounding text, which Completions are not aware of. """ return self.start == other.start and \ self.end == other.end and \ self.text == other.text
def test_AnyOfObject(): class Foo(jst.JSONHasTraits): intval = T.Integer() flag = T.Bool() class Bar(jst.JSONHasTraits): strval = T.Unicode() flag = T.Bool() class FooBar(jst.AnyOfObject): _classes = [Foo, Bar] FooBar(strval='hello', flag=True) FooBar(intval=5, flag=True) with pytest.raises(T.TraitError): FooBar(strval=666, flag=False) with pytest.raises(T.TraitError): FooBar(strval='hello', flag='bad arg') with pytest.raises(T.TraitError): FooBar(intval='bad arg', flag=False) with pytest.raises(T.TraitError): FooBar(intval=42, flag='bad arg') # Test from_dict FooBar.from_dict({'strval': 'hello', 'flag': True}) FooBar.from_dict({'intval': 42, 'flag': False})