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
python类Bool()的实例源码
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})
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