staircase icon indicating copy to clipboard operation
staircase copied to clipboard

Replace assert statements

Open venaturum opened this issue 5 years ago • 3 comments

Asserts should be used to test conditions that should never happen. The purpose is to crash early in the case of a corrupt program state.

Exceptions should be used for errors that can conceivably happen, and you should almost always create your own Exception classes.

For example, if you're writing a function to read from a configuration file into a dict, improper formatting in the file should raise a ConfigurationSyntaxError, while you can assert that you're not about to return None.

In your example, if x is a value set via a user interface or from an external source, an exception is best.

If x is only set by your own code in the same program, go with an assertion.

venaturum avatar Jan 12 '21 11:01 venaturum

This LGTM, I don't see any assert out of place, I would close this issue. All asserts I found were in the test suit where assert is ok.

PabloRuizCuevas avatar Oct 24 '22 07:10 PabloRuizCuevas

Hmm, do you have a filter on your search directories by any chance? A quick skim of the search results in VS Code shows around 15+ instances of assert statements inside staircase/staircase.

venaturum avatar Oct 24 '22 11:10 venaturum

ups yes, you are right.

PabloRuizCuevas avatar Oct 24 '22 12:10 PabloRuizCuevas