Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@accepts(s=Set(int))
def sum_set_items(s):
return sum(s)
@accepts(a=All(Number, int), b=All(Number, int))
def add_integers(a, b):
return a + b
@accepts(a=Any(int, float), b=Any(int, float))
def add_ints_or_floats(a, b):
return a + b
@accepts(a=int, b=int, coerce_type=True)
def coerce_type_and_add_ints(a, b):
return a + b
@accepts(l=List(int))
def sum_list(l):
return sum(l)
@accepts(d=Dict(key=int, value=object))
def sum_keys(d):
return sum(d.keys())
@accepts(a=int, b=int)
def add_ints(a, b):
return a + b
@accepts(t=Tuple(int))
def sum_tuple(t):
return sum(t)
@accepts(d=Dict(int, Dict(basestring, float)))
def nested_data_structure(d):
return
def test_typed_fn(self):
# ensure no error is raised and function behaves as intended
assert add_ints(1, 2) == 3
# ensure invalid types cause TypeErrors to be raised
with self.assertRaises(InputTypeError):
add_ints(1.0, 2.0)