fixed ex_36
This commit is contained in:
parent
90d638cfae
commit
1daf019b2c
21
ex_36.py
21
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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user