[Python-Dev] PEP 495 accepted
Tim Peters
tim.peters at gmail.com
Tue Sep 22 19:34:19 CEST 2015
[Tim]
>> Sure - no complaint. I was just saying that in the specific,
>> complicated, contrived expression Nick presented, that it always
>> returns False (no matter which aware datetime he starts with) would be
>> more of a head-scratcher than if it raised a "can't compare naive and
>> aware datetimes" exception instead.
[Guido]
> And yet I think the desired behavior of == requires us to return False.
Yes - we remain in violent agreement on all points here.
> I think we should change this in the PEP, except I can't find where
> the PEP says == should raise an exception in this case.
It doesn't - the only comparison behavior changed by the PEP is in
case of interzone comparison when at least one comparand is a "problem
time" (which can only happen with a post-495 tzinfo). Then "==" is
always False. That hack is the ugliest part of the PEP, but was
needed to preserve the hash invariant (d1 == d2 implies hash(d1) ==
hash(d2)).
BTW, while the PEP doesn't spell this out, trichotomy can fail in some
such cases (those where "==" would have returned True had it not been
forced to return False - then "<" and ">" will also be False).
In any case, nothing changes for any case of aware-vs-naive comparison.
More information about the Python-Dev
mailing list