Complete worked example
python
def inspect_example(kinds):
errors = [ValueError('bad value') if kind == 'value' else TypeError('bad type')
for kind in kinds]
report = {'value': 0, 'type': 0}
try:
if errors:
raise ExceptionGroup('owned batch', errors)
except* ValueError as group:
report['value'] = len(group.exceptions)
except* TypeError as group:
report['type'] = len(group.exceptions)
return report- Reasoning
- Input labels create ValueError or TypeError instances in order. A nonempty batch raises the group, and the two except* handlers receive their corresponding matching subsets. For value, type and value, the report records two value errors and one type error.