How to use runtype - 10 common examples

To help you get started, we’ve selected a few runtype examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github madisonmay / Runtype / tests / test_typed.py View on Github external
@accepts(s=Set(int))
def sum_set_items(s):
    return sum(s)
github madisonmay / Runtype / tests / test_typed.py View on Github external
@accepts(a=All(Number, int), b=All(Number, int))
def add_integers(a, b):
    return a + b
github madisonmay / Runtype / tests / test_typed.py View on Github external
@accepts(a=Any(int, float), b=Any(int, float))
def add_ints_or_floats(a, b):
    return a + b
github madisonmay / Runtype / tests / test_typed.py View on Github external
@accepts(a=int, b=int, coerce_type=True)
def coerce_type_and_add_ints(a, b):
    return a + b
github madisonmay / Runtype / tests / test_typed.py View on Github external
@accepts(l=List(int))
def sum_list(l):
    return sum(l)
github madisonmay / Runtype / tests / test_typed.py View on Github external
@accepts(d=Dict(key=int, value=object))
def sum_keys(d):
    return sum(d.keys())
github madisonmay / Runtype / tests / test_typed.py View on Github external
@accepts(a=int, b=int)
def add_ints(a, b):
    return a + b
github madisonmay / Runtype / tests / test_typed.py View on Github external
@accepts(t=Tuple(int))
def sum_tuple(t):
    return sum(t)
github madisonmay / Runtype / tests / test_typed.py View on Github external
@accepts(d=Dict(int, Dict(basestring, float)))
def nested_data_structure(d):
    return
github madisonmay / Runtype / tests / test_typed.py View on Github external
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)