MHKiT-Software / MHKiT-Python

MHKiT-Python provides the marine renewable energy (MRE) community tools for data processing, visualization, quality control, resource assessment, and device performance.
https://mhkit-software.github.io/MHKiT/
BSD 3-Clause "New" or "Revised" License
47 stars 45 forks source link

Assert Statements are for Debugging #242

Open ssolson opened 1 year ago

ssolson commented 1 year ago

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 commented 1 year ago

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

image

onedeeper commented 11 months ago

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!

ssolson commented 10 months ago

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!