def test_works_with_Type_function(self): from typecheck import Type, Function def foo(*vargs): return vargs assert isinstance(Type(foo), Function)
def test_works_with_Type_instancemethod_classic(self): from typecheck import Type, Function class Foo: def foo(*vargs): return vargs assert isinstance(Type(Foo().foo), Function)
def test_works_with_Type_call_method_classic(self): from typecheck import Type, Function class Foo: def __call__(self, *vargs): return vargs assert isinstance(Type(Foo()), Function)
def test_works_with_Type_instancemethod_newstyle(self): from typecheck import Type, CheckerFunction class Foo(object): def foo(self, *vargs): return vargs assert isinstance(Type(Foo().foo), CheckerFunction)
def test_works_with_Type_staticmethod_newstyle(self): from typecheck import Type, Function class Foo(object): @staticmethod def foo(*vargs): return vargs assert isinstance(Type(Foo.foo), Function)
def test_works_with_Type_staticmethod_classic(self): from typecheck import Type, CheckerFunction class Foo: @staticmethod def foo(*vargs): return vargs assert isinstance(Type(Foo.foo), CheckerFunction)
def __init__(self, set_list): self.type = set(set_list) self._types = [Type(t) for t in self.type] # self._type is used to build _TC_TypeError if len(self._types) > 1: self._type = Or(*self.type) elif len(self._types) == 1: # XXX Is there an easier way to get this? t = self.type.pop() self._type = t self.type.add(t)
def test_Type_uses_it(self): from typecheck import Type t = Type(set([int, float])) assert isinstance(t, Set)
def __init__(self, *types): #import ipdb; ipdb.set_trace() if not types: raise TypeError("Must supply at least one type to __init__()") self._types = [Type(t) for t in types] self.type = [t.type for t in self._types]
def __init__(self, val): self._type = Type(val) self.type = self
def test_used_by_Type(self): from typecheck import Type from typecheck.mixins import _UnorderedIteratorMixin uim = Type(self.Iter(float, int)) assert isinstance(uim, _UnorderedIteratorMixin)