Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.iterable_type = iterable_type
def validate(self, value):
return (
isinstance(value, self.iterable_type) and
all([is_type(i, self.item_type) for i in value])
)
class List(Iterable):
def __init__(self, item):
super(List, self).__init__(item, iterable_type=list)
class Tuple(Iterable):
def __init__(self, item):
super(Tuple, self).__init__(item, iterable_type=tuple)
class Set(Iterable):
def __init__(self, item):
super(Set, self).__init__(item, iterable_type=set)
def is_type(value, argtype):
"""
Like isinstance, but also supports runtype's Or and And psuedotypes.
"""
if isinstance(argtype, BaseType):
class Iterable(BaseType):
def __init__(self, item, iterable_type=IterableType):
self.item_type = item
self.iterable_type = iterable_type
def validate(self, value):
return (
isinstance(value, self.iterable_type) and
all([is_type(i, self.item_type) for i in value])
)
class List(Iterable):
def __init__(self, item):
super(List, self).__init__(item, iterable_type=list)
class Tuple(Iterable):
def __init__(self, item):
super(Tuple, self).__init__(item, iterable_type=tuple)
class Set(Iterable):
def __init__(self, item):
super(Set, self).__init__(item, iterable_type=set)
)
class List(Iterable):
def __init__(self, item):
super(List, self).__init__(item, iterable_type=list)
class Tuple(Iterable):
def __init__(self, item):
super(Tuple, self).__init__(item, iterable_type=tuple)
class Set(Iterable):
def __init__(self, item):
super(Set, self).__init__(item, iterable_type=set)
def is_type(value, argtype):
"""
Like isinstance, but also supports runtype's Or and And psuedotypes.
"""
if isinstance(argtype, BaseType):
return argtype.validate(value)
else:
return isinstance(value, argtype)