MHKiT-Python icon indicating copy to clipboard operation
MHKiT-Python copied to clipboard

Assert Statements are for Debugging

Open ssolson opened this issue 2 years ago • 3 comments

Currently MHKiT uses assert staements in its production code (primarilty for type checking functional inputs). As stated in the docs (https://docs.python.org/3/reference/simple_stmts.html#the-assert-statement) assert stements are for debugging.

We should raise an error if the user does not pass the correct information.

So going forward we would convert:

assert isinstance(station_number, (str, type(None))), (f'station_number must be  of type string')

to this

if not isinstance(station_number, (str, type(None))):
    raise ValueError(f'station_number must be of type string. Got: {station_number}')

ssolson avatar May 19 '23 16:05 ssolson

Here is an article covering this idea in more detail: https://snyk.io/blog/the-dangers-of-assert-in-python/

image

ssolson avatar May 19 '23 16:05 ssolson

Hello! I'm trying to get my feet wet with some python open source. This seems straight forward so I'm happy to take care of it. Does this seem like a good first issue? Thanks!

onedeeper avatar Jul 15 '23 05:07 onedeeper

Hello! I'm trying to get my feet wet with some python open source. This seems straight forward so I'm happy to take care of it. Does this seem like a good first issue? Thanks!

@onedeeper I am so sorry I missed this. Yes this would be a great first issue. Please lmk if you need any help contributing!

ssolson avatar Aug 10 '23 16:08 ssolson