Correctness¶
Keep bad data out and keep objects consistent when something goes wrong halfway.
-
validate_args,check_typeandenforce_types: reject bad input with an error that names the parameter. -
revert_on_failure,Transactionandtransactional: undo changes when a call fails.
Which one?¶
| You want to | Use |
|---|---|
Check a business rule (amount > 0, not empty) |
validate_args |
Check that an argument is an int or str |
check_type |
| Make your type hints true at runtime | enforce_types |
| Restore an object's attributes if a method fails | revert_on_failure |
| Undo side effects (files, payments) when a step fails | transactional |