MCPcopy Index your code
hub / github.com/dabeaz-course/python-mastery / wrapper

Function wrapper

Solutions/8_1/validate.py:79–101  ·  view source on GitHub ↗
(*args, **kwargs)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

appendMethod · 0.80
checkMethod · 0.45

Tested by

no test coverage detected