WasatchPhotonics / ENLIGHTEN

Open-source spectroscopy application for controlling and taking measurements from Wasatch Photonics spectrometers.
https://wasatchphotonics.com/product-category/software/
MIT License
3 stars 6 forks source link

Sb no truthy #331

Closed samiebee43 closed 10 months ago

samiebee43 commented 10 months ago

Reviewing the code that colors the laser button I didn't find any obvious cause for a gray button that says "Turn Laser Off".

But I did see this strange utility call. It's defined in Wasatch.PY.

def truthy(flag):
    if flag is None:
        return False

    try:
        if len(flag) > 0:
            return True
    except:
        pass

    return True if flag else False

This is the same thing as how Python already treats values in if-statements.

>>> bool(None)
False
>>> bool([])
False
>>> bool(0)
False
>>> bool("")
False

>>> truthy(None)
False
>>> truthy([])
False
>>> truthy(0)
False
>>> truthy("")
False

# also note that
if bool(x):
    something()
# is the same as
if x:
    something()

Is there any reason this was done besides an abundance of caution in the wake of uncertainty how python treats these cases?

mzieg commented 10 months ago

abundance of caution in the wake of uncertainty how python treats these cases?

That was probably it. I agree that removing this function from Wasatch.PY is a good idea, and will only help troubleshooting issues in the future.