[Python-Dev] PEP 495 accepted

Guido van Rossum guido at python.org
Tue Sep 22 18:55:35 CEST 2015


On Tue, Sep 22, 2015 at 9:47 AM, Tim Peters <tim.peters at gmail.com> wrote:

> [Tim]
> >>> ...
> >>> The
> >>> top-level operation on the RHS is datetime.fromtimestamp().  However,
> >>> it didn't pass a tzinfo, so it creates a naive datetime.  Assuming dt
> >>> was aware to begin with, the attempt to compare will always (gap or
> >>> not) raise an exception.
>
> [Tim]
> >> Oops!  In current Python, comparing naive and aware via `==` just
> >> returns False.  That's even more confusing ;-)
>
> [Guido]
> > Hm, but that's in general how == is *supposed* to work between objects of
> > incompatible types. < and > are supposed to fail but == is supposed to
> > return False (the __eq__ should return NotImplemented). If == ever
> raises an
> > exception, having two different objects as dict keys can cause random,
> > hard-to-debug failures.
>
> 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.
>

And yet I think the desired behavior of == requires us to return False. 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.


> That's why, whenever anyone is confused by anything they see in a
> Python program, they should post all their code verbatim to
> Python-Dev, prefaced with a "Doesn't work!  Fix it." comment ;-)
>

Oh, it would be so much better if they posted their code!

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150922/254f5801/attachment.html>


More information about the Python-Dev mailing list