[BangPypers] Should equality (__eq__) be dependent on the typeof object?

Shabda Raaj shabda at agiliq.com
Tue Sep 10 08:26:35 CEST 2013


See this:

In [3]: OrderedDict(a=1) == {"a": 1}
Out[3]: True


> "Today" (10/Sep) is not equal to "right now" (10/Sep, 11:28 am).

> Makes sense no?

True, but datetime.date(2013, 1, 1) == datetime.datetime(2013, 1, 1)
should still get me true. (The argument being, date.__eq__ should
only care about the date components, it shouldn't even care about the
time components. However datetime.__eq__ should care about
the time components. However you want the __eq__ to be symmetric, so
my argument doesn't work)



On Tue, Sep 10, 2013 at 11:30 AM, Noufal Ibrahim <noufal at nibrahim.net.in>wrote:

> Shabda Raaj <shabda at agiliq.com> writes:
>
> >> I'd expect it to be False. There will be a small amount of time between
> > the two invocations and the time will change
> >
> > Ok, that makes sense. Should have written a better test case. What about
> > this.
> >
> >>>> datetime.datetime(2013, 1, 1) == datetime.date(2013, 1, 1)
> > False
> >>>> datetime.datetime.today() == datetime.date.today()
> > False
>
> I think that's reasonable.
>
> "Today" (10/Sep) is not equal to "right now" (10/Sep, 11:28 am).
>
> Makes sense no?
>
> However,
>
> >>> x, y = datetime.datetime(2013, 1, 1), datetime.date(2013, 1, 1)
> >>> x.date() == y
> True
>
> which is much more sensible.
>
> For what it's worth, I think this whole business of dates and times is a
> mess.
>
>
> --
> Cordially,
> Noufal
> http://nibrahim.net.in
>



-- 
Thanks,
Shabda

Agiliq.com - Building Amazing Apps
agiliq.com/blog/ | github.com/agiliq
US: +13152854388 | IN: +919949997612 | Skype: shabda.raaj
Our Android Apps <https://play.google.com/store/apps/developer?id=Agiliq> | Our
iOS Apps <https://itunes.apple.com/us/artist/agiliq/id407918088>


More information about the BangPypers mailing list