If contract violtions raised distinct subtypes of AssertionError, it would be possible to programmatically handle various kinds of contract violation. I imagine something like:
class PreconditionError(AssertionError):
"""An AssertionError raised due to violation of a precondition."""
class PostconditionError(AssertionError):
"""An AssertionError raised due to violation of a postcondition."""
# Then, to replace `if condition: assert foo, description` in each place:
if precondition and predicate(rargs): # and similar for postconditions etc.
raise PreconditionError(description)
This could be used by a fuzzer - e.g. HypothesisWorks/hypothesis#1474 - to automatically discover valid inputs, by distinguishing between invalid input and other errors.
If contract violtions raised distinct subtypes of
AssertionError
, it would be possible to programmatically handle various kinds of contract violation. I imagine something like:This could be used by a fuzzer - e.g. HypothesisWorks/hypothesis#1474 - to automatically discover valid inputs, by distinguishing between invalid input and other errors.