Wrapping third party code
attempt runs an exception-throwing thunk lazily and maps expected exceptions into the typed error channel. Re-raise unexpected exceptions from the mapper so they stay defects:
@
@(frozen=True)
class (E.):
:
def (: ) -> E.[, ]:
def (: ) -> :
if (, json.):
return ()
raise # anything else stays a defect
return E.(lambda: json.(), )More examples: test_attempt.py.