| 73 | |
| 74 | @wraps(func) |
| 75 | def wrapper(*args, **kwargs): |
| 76 | bound = sig.bind(*args, **kwargs) |
| 77 | errors = [] |
| 78 | |
| 79 | # Enforce argument checks |
| 80 | for name, validator in annotations.items(): |
| 81 | try: |
| 82 | validator.check(bound.arguments[name]) |
| 83 | except Exception as e: |
| 84 | errors.append(f' {name}: {e}') |
| 85 | |
| 86 | if errors: |
| 87 | raise TypeError('Bad Arguments\n' + '\n'.join(errors)) |
| 88 | |
| 89 | result = func(*args, **kwargs) |
| 90 | |
| 91 | # Enforce return check (if any) |
| 92 | if retcheck: |
| 93 | try: |
| 94 | retcheck.check(result) |
| 95 | except Exception as e: |
| 96 | raise TypeError(f'Bad return: {e}') from None |
| 97 | return result |
| 98 | |
| 99 | return wrapper |
| 100 | |