return val is None
+@WithDesc("ValueNone")
+def TValueNone(val):
+ """Checks if the given value is L{constants.VALUE_NONE}.
+
+ """
+ return val == constants.VALUE_NONE
+
+
@WithDesc("Boolean")
def TBool(val):
"""Checks if the given value is a boolean.
return isinstance(val, list)
+@WithDesc("Tuple")
+def TTuple(val):
+ """Checks if the given value is a tuple.
+
+ """
+ return isinstance(val, tuple)
+
+
@WithDesc("Dictionary")
def TDict(val):
"""Checks if the given value is a dictionary.
def TOr(*args):
- """Combine multiple functions using an AND operation.
+ """Combine multiple functions using an OR operation.
"""
def fn(val):
return TOr(TNone, test)
+def TMaybeValueNone(test):
+ """Used for unsetting values.
+
+ """
+ return TMaybe(TOr(TValueNone, test))
+
+
# Type aliases
#: a non-empty string
#: Maybe a dictionary (dict or None)
TMaybeDict = TMaybe(TDict)
+#: Maybe a list (list or None)
+TMaybeList = TMaybe(TList)
+
#: a non-negative integer (value >= 0)
TNonNegativeInt = \
TAnd(TInt, WithDesc("EqualOrGreaterThanZero")(lambda v: v >= 0))
TRelativeJobId = WithDesc("RelativeJobId")(TNegativeInt)
-def TInstanceOf(my_inst):
- """Checks if a given value is an instance of my_inst.
+def TInstanceOf(cls):
+ """Checks if a given value is an instance of C{cls}.
+
+ @type cls: class
+ @param cls: Class object
"""
- desc = WithDesc("Instance of %s" % (Parens(my_inst), ))
- return desc(lambda val: isinstance(val, my_inst))
+ name = "%s.%s" % (cls.__module__, cls.__name__)
+
+ desc = WithDesc("Instance of %s" % (Parens(name), ))
+
+ return desc(lambda val: isinstance(val, cls))
def TListOf(my_type):