[Datetime-SIG] Another round on error-checking

Tim Peters tim.peters at gmail.com
Thu Sep 3 18:58:22 CEST 2015


[Alex]
> I wish we could have a design where fold is always ignored when you have a
> single tzinfo.

Me too - and you tried very hard to make that so.  Valiant effort!

> The reason we cannot has been explained several times in
> this thread.  The core reason is possibly a mistake in the original design
> that permitted cross-zone arithmetic and comparison.  If == was defined so
> that no two instances with different tzinfo ever compare equal and <, - and
> friends are only defined for datetimes sharing the tzinfo, we would not have
> this problem.  Recall that datetime was designed at the time when it was
> thought that mixing bytes and unicode was a good idea.  We all know what it
> took to fix that wart.

It was also designed at a time when Python was just starting to stop
;-) allowing comparisons between _any_ two objects.  Things like

    1 < "1"
    {10: 20} < [None]

were true near that time.  Why?  "Because" in senseless cases (both
comparands said "not implemented"), sometimes the string names of the
types were compared instead, and "int" < "str" and "dict" < "list" are
true.

Compared to stuff like that, doing timeline arithmetic for interzone
comparisons seemed to be a welcome case of principled sanity ;-)

But there's no question (in my mind) that if datetime had been
designed today, interzone comparisons would be disallowed (except for
"==" always saying False and "!=" always True).


More information about the Datetime-SIG mailing list