[Python-Dev] PEP 495 accepted (original) (raw)
Guido van Rossum guido at python.org
Tue Sep 22 19:57:37 CEST 2015
- Previous message (by thread): [Python-Dev] PEP 495 accepted
- Next message (by thread): [Python-Dev] PEP 495 accepted
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Sep 22, 2015 at 10:34 AM, Tim Peters <tim.peters at gmail.com> wrote:
[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.
And I guess we can't make < and > raise an exception for backward compatibility reasons. :-(
-- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20150922/513ad16e/attachment.html>
- Previous message (by thread): [Python-Dev] PEP 495 accepted
- Next message (by thread): [Python-Dev] PEP 495 accepted
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]