Why are timezone aware and naive datetimes not distinct classes?
roy at panix.com
Fri Mar 8 19:41:27 CET 2013
To make a long (and painful) story short, I've got a (large) list of
datetimes, and was getting some bizarre errors working with it. One of
the things I tried while debugging the problem was verifying that all
the elements of the list were indeed datetimes:
In : set(type(foo) for foo in x)
Well, it turns out, one of them was a timezone-aware datetime, and all
the others were naive! I finally figured it out when I tried
TypeError: can't compare offset-naive and offset-aware datetimes
So, the question is, WHY aren't aware and naive datetimes separate
classes? They share many attributes and methods, but not all. It seems
like they should both be subclasses of some common BaseDatetime. Was
not splitting them into two classes a deliberate design decision?
More information about the Python-list