sot / chandra_time

Convert between various time formats relevant to Chandra.
https://sot.github.io/Chandra.Time
BSD 3-Clause "New" or "Revised" License
4 stars 1 forks source link

Fix Py3 issue - hasattr raises exception from getattr instead of swallowing #25

Closed taldcroft closed 7 years ago

taldcroft commented 7 years ago

In Py2 and Py3, hasattr() works by trying to get the attribute. But (I think) in Py2 any exception gets re-raised as AttributeError while in Py3 the actual exception gets raised. If it isn't AttributeError then hasattr() just raises an exception instead of giving False.

See the Hacker News thread "hasattr considered harmful" for background.

taldcroft commented 7 years ago

BTW this was causing a test to fail, so no updates to tests are needed.

jeanconn commented 7 years ago

I don't completely understand the attribute handling in Time.py to understand the fix, but don't see a problem with it. :+1: