[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2018-07-05 Thread Paul Ganssle


Change by Paul Ganssle :


--
nosy: +p-ganssle

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2016-09-18 Thread Mark Dickinson

Changes by Mark Dickinson :


--
nosy:  -mark.dickinson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2016-09-10 Thread Alexander Belopolsky

Changes by Alexander Belopolsky :


--
versions: +Python 3.7 -Python 3.3

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2013-08-12 Thread Eric Snow

Eric Snow added the comment:

This bit me today (under 2.7).

--
nosy: +eric.snow

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2013-08-12 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

Eric,

Could you share details of your use-case?  My experience with subclassing from 
basic python types including date/time has been mostly negative.  The problem 
is that when I subclass, I want to inherit the rich set of operations such as 
+, -, *, etc., and add a few methods of my own.  After that, I want to always 
use instances of my subclass instead of the stdlib one.  This does not work 
because adding instances of my subclass returns an instance of the superclass 
unless I override __add__ explicitly. (See   #2267.)  This kills all benefits 
of subclassing as compared to containment.

These days I try to stay away from subclassing date/time, int/float, or 
anything like that and thus have little incentive to resolve this issue.  And 
it does not look like we have a workable solution.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2013-08-12 Thread Eric Snow

Eric Snow added the comment:

I'm doing some string-based serialization of datetimes and need to be able to 
specify the type somewhat declaratively.  So I'm using a datetime subclass.  
This is more or less the code I'm using:


class Timestamp(datetime.datetime):

def __new__(cls, raw_value, *args, **kwargs):
if not args and not kwargs:
return cls.fromtimestamp(int(raw_value))
else:
return super(Timestamp, cls).__new__(cls, raw_value,
 *args, **kwargs)

def __str__(self):
return str(int(time.mktime(self.timetuple(


Incidently, the whole equality testing thing didn't actually cause a problem.  
It was comparing against the result of `datetime.utcnow()` which has 
microseconds (and my Timestamp instance didn't).  Clearing out the microseconds 
resolved the failure so I wasn't actually bitten by this issue after all.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2011-01-11 Thread Alexander Belopolsky

Changes by Alexander Belopolsky belopol...@users.sourceforge.net:


--
keywords:  -patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2010-12-01 Thread Alexander Belopolsky

Changes by Alexander Belopolsky belopol...@users.sourceforge.net:


--
resolution:  - postponed
versions: +Python 3.3 -Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2010-06-25 Thread Alexander Belopolsky

Alexander Belopolsky belopol...@users.sourceforge.net added the comment:

 Deprecating the feature for 3.x is certainly an option.
 May be a little drastic though.

How drastic would be to stop subclassing datetime from date in 3.2?  After all, 
we don't subclass float form int.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2010-06-25 Thread Nick Coghlan

Nick Coghlan ncogh...@gmail.com added the comment:

If you can articulate the benefits of splitting them apart, it would be worth 
making the case for doing so on python-dev. I'm having a hard time picturing 
what anyone could be doing such that it would break their code, but it's still 
definitely a backwards incompatible change.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2010-05-25 Thread Alexander Belopolsky

Alexander Belopolsky belopol...@users.sourceforge.net added the comment:

I am leaning towards won't fix.  Any objections?

--
assignee:  - belopolsky
nosy: +belopolsky -Alexander.Belopolsky
versions:  -Python 2.5, Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2010-05-25 Thread Jess Austin

Jess Austin jess.aus...@gmail.com added the comment:

Could you provide some reasoning for such a resolution?  I had thought that 
won't fix indicated that the issue wasn't actually an error in behavior.

I grant that most people will never see this particular error, but it is an 
error.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2010-05-25 Thread Alexander Belopolsky

Alexander Belopolsky belopol...@users.sourceforge.net added the comment:

 Could you provide some reasoning for such a resolution? 
 I had thought that won't fix indicated that the issue
 wasn't actually an error in behavior.

No, that would be invalid.  IMO, won't fix is for bugs were cost of fixing 
them outweighs the benefits.  Here is a typical example: issue8309 Sin(x) is 
Wrong.

Here, however I am torn between won't fix and invalid.  As I said in my 
previous comment:


Note, however that the problematic behavior is due to D/DT
classes implementor's choice not to derive DT from D.  Whether
resulting violation of the symmetry of equality is a bug in python or
D/DT implementation is at least an open question.


I don't mind keeping this open if there is a hope that someone will come up 
with a working solution.  The current patch is not a solution.

--
priority: normal - low
stage:  - needs patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2010-05-25 Thread Nick Coghlan

Nick Coghlan ncogh...@gmail.com added the comment:

I'd suggest leaving it open - the current situation is definitely suboptimal, 
but it is likely to take some close scrutiny to get it to behave nicely.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2010-05-25 Thread Ray.Allen

Ray.Allen ysj@gmail.com added the comment:

Date and Datetime comparison is not defined and not documented, and until we 
find a nice way to implement the comparison, we should just let this comparison 
raise NotImpelemented.

--
nosy: +ysj.ray

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2010-05-25 Thread Nick Coghlan

Nick Coghlan ncogh...@gmail.com added the comment:

Deprecating the feature for 3.x is certainly an option. May be a little drastic 
though.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2010-04-28 Thread Nick Coghlan

Nick Coghlan ncogh...@gmail.com added the comment:

I think I'll concur with the this is a mess assessment.

Given that state of affairs, punting on this until 3.2 (at the earliest).

--
assignee: ncoghlan - 
versions: +Python 3.2 -Python 2.4, Python 2.7, Python 3.0, Python 3.1

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2010-04-21 Thread Alexander Belopolsky

Alexander Belopolsky alexander.belopol...@gmail.com added the comment:

There is another inconsistency that this patch does not seem to cure.  With 
patch applied and D and DT defined as in OP,

 D(1900,1,1)  DT(1900,1,1)
True

but

 DT(1900,1,1)  D(1900,1,1)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: can't compare DT to D

and

 date(1900,1,1)  datetime(1900,1,1)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: can't compare datetime.datetime to datetime.date

Note that without the patch,

 D(1900,1,1)  DT(1900,1,1)
False

but both behaviors seem to be wrong.

--
nosy: +Alexander.Belopolsky

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2010-04-21 Thread Alexander Belopolsky

Alexander Belopolsky alexander.belopol...@gmail.com added the comment:

Upon further reflection I am -1 on this patch.  First, as implemented this 
patch changes behavior of an explicit invocation of date.__eq__.  The patch 
proposes to remove the following tests:

-# Neverthelss, comparison should work with the base-class (date)
-# projection if use of a date method is forced.
-self.assert_(as_date.__eq__(as_datetime))
-different_day = (as_date.day + 1) % 20 + 1
-self.assert_(not as_date.__eq__(as_datetime.replace(day=
- different_day)))

Second, the patch introduces dependence of the baseclass method 
(date_richcompare) on a particular subclass (PyDateTime_Check).  This is 
against OOP principles.

I am not sure how the equality not symmetric issue can be fixed.  In my 
opinion current datetime implementation is fighting OOP and violating the 
substitution principle in an attempt to prevent date to datetime comparison.  I 
would prefer seeing one of two things: either datetime not inheriting from date 
or making datetime to date comparison compare date part alone.  Once you stop 
fighting OOP principles, symmetry of equality for subclasses will follow from 
that for the base class automatically.

Given that either of these solutions means a major change, I think it is best 
to leave the things as they are now.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2010-04-21 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +mark.dickinson

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2010-04-21 Thread Jess Austin

Jess Austin jess.aus...@gmail.com added the comment:

To be systematic, without the patch:

 D(1900, 1, 1)  DT(1900, 1, 1)
False
 D(1900, 1, 1)  DT(1900, 1, 1)
False
 DT(1900, 1, 1)  D(1900, 1, 1)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: can't compare DT to D
 DT(1900, 1, 1)  D(1900, 1, 1)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: can't compare DT to D


with the patch:

 D(1900, 1, 1)  DT(1900, 1, 1)
True
 D(1900, 1, 1)  DT(1900, 1, 1)
False
 DT(1900, 1, 1)  D(1900, 1, 1)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: can't compare DT to D
 DT(1900, 1, 1)  D(1900, 1, 1)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: can't compare DT to D


It might seem like the latter behavior is marginally better, but really this is 
just a mess, since a date-datetime comparison TypeErrors in all directions.  I 
appreciate Alexander's more experienced perspective, but it's not obvious to me 
that this problem is insoluble simply due to OOP algebra.  I'm going to keep 
tinkering with this to see if there isn't a way to satisfy his concerns AND fix 
these bugs WITHOUT breaking the established (and admittedly anti-OOP) behavior 
that dates are not equal to datetimes.

(Incidentally, the test I removed still seems to be an arbitrary ad-hoc 
requirement that subclasses of date behave differently than date itself.  I 
don't see how one could rely on this given the other inconsistencies with date 
subclasses, and so violating this in order to fix more serious problems seems 
acceptable.)

I'm reminded of the set and frozenset situation, which seems almost dual to 
this one.  set and frozenset don't inherit from each other, but they do 
compare.  This seems to bite you only when you try to redefine comparison in 
subclasses.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2010-04-21 Thread Alexander Belopolsky

Alexander Belopolsky alexander.belopol...@gmail.com added the comment:

On Wed, Apr 21, 2010 at 2:33 PM, Jess Austin rep...@bugs.python.org wrote:
..
 It might seem like the latter behavior is marginally better, but really this 
 is just a mess, since a date-datetime comparison TypeErrors in all
 directions.  I appreciate Alexander's more experienced perspective, but it's 
 not obvious to me that this problem is insoluble simply due to OOP
 algebra.  I'm going to keep tinkering with this to see if there isn't a way 
 to satisfy his concerns AND fix these bugs WITHOUT breaking the
 established (and admittedly anti-OOP) behavior that dates are not equal to 
 datetimes.


I certainly don't have a proof that this is impossible, so best of
luck.  Note, however that the problematic behavior is due to D/DT
classes implementor's choice not to derive DT from D.  Whether
resulting violation of the symmetry of equality is a bug in python or
D/DT implementation is at least an open question.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2010-01-13 Thread Nick Coghlan

Changes by Nick Coghlan ncogh...@gmail.com:


--
assignee:  - ncoghlan
nosy: +ncoghlan

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2009-03-26 Thread Jack Diederich

Jack Diederich jackd...@gmail.com added the comment:

+1

Patch and tests work for me.  Uploaded a patch that is identical except
the file paths are fixed.

Was the old behavior stable across compilers anyway?  It memcmpared two
different structs and IIRC only the first item of each struct is
guaranteed to be at the start of the memory location.  No?

With this patch only same-struct objects are memcmpared.

--
nosy: +jackdied
Added file: http://bugs.python.org/file13419/issue5516_trunk.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2009-03-23 Thread Jess Austin

Jess Austin jess.aus...@gmail.com added the comment:

The attached patch fixes this issue, and updates the tests.  Contrary to
my initial impression, it seems that a previous developer knew of this
behavior and thought it correct; see the comment of the test I deleted.
 I left memcmp() in.

--
keywords: +patch
Added file: http://bugs.python.org/file13403/issue5516.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5516] equality not symmetric for subclasses of datetime.date and datetime.datetime

2009-03-18 Thread Jess Austin

Changes by Jess Austin jess.aus...@gmail.com:


--
title: equality not reflexive for subclasses of datetime.date and 
datetime.datetime - equality not symmetric for subclasses of datetime.date and 
datetime.datetime

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5516
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com