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