From 1daf019b2c9b144b81376f3c78de86aec250055b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kn=C3=BCttel?= Date: Wed, 9 Jan 2019 14:38:46 +0100 Subject: [PATCH] fixed ex_36 --- ex_36.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ex_36.py b/ex_36.py index 28c1f65..91f463e 100644 --- a/ex_36.py +++ b/ex_36.py @@ -1,4 +1,21 @@ +import sys def check_range(f): - def wrapper(**kwargs): - for k,v in + if sys.version_info.major < 3 or sys.version_info.minor < 6: + raise RuntimeError("check_range requires python >= 3.6") + def wrapper(*args, **kwargs): + total_args = list(args) + list(kwargs.values()) + for argv, (argname, argrange) in zip(total_args, f.__annotations__.items()): + if(argv < argrange[0] or argv > argrange[1]): + raise ValueError("Argument {} ({}) out or range {}".format(argname, argv, argrange)) + return f(*args, **kwargs) + return wrapper + +@check_range +def f(a: (0, 100), b: (100, 300)): + return a + b + +if( __name__ == "__main__"): + f(1, 101) + f(-2, 400) +