提交 a9a8ff2b authored 作者: Pascal Lamblin's avatar Pascal Lamblin

In filter, raise TypeError or ValueError.

type.is_valid_value relies on filter() raising either TypeError or ValueError for invalid values, not AssertionError.
上级 84ac684c
...@@ -39,7 +39,10 @@ class MyType(Type): ...@@ -39,7 +39,10 @@ class MyType(Type):
def filter(self, x, strict=False, allow_downcast=None): def filter(self, x, strict=False, allow_downcast=None):
# Dummy filter: we want this type to represent strings that # Dummy filter: we want this type to represent strings that
# start with `self.thingy`. # start with `self.thingy`.
assert isinstance(x, basestring) and x.startswith(self.thingy) if not isinstance(x, basestring):
raise TypeError("Invalid type")
if not x.startswith(self.thingy):
raise ValueError("Invalid value")
return x return x
class MyOp(Op): class MyOp(Op):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论