@@ -1065,13 +1065,13 @@ def tzinfo(self):
10651065
10661066 def __eq__ (self , other ):
10671067 if isinstance (other , time ):
1068- return self ._cmp (other ) == 0
1068+ return self ._cmp (other , allow_mixed = True ) == 0
10691069 else :
10701070 return False
10711071
10721072 def __ne__ (self , other ):
10731073 if isinstance (other , time ):
1074- return self ._cmp (other ) != 0
1074+ return self ._cmp (other , allow_mixed = True ) != 0
10751075 else :
10761076 return True
10771077
@@ -1099,7 +1099,7 @@ def __gt__(self, other):
10991099 else :
11001100 _cmperror (self , other )
11011101
1102- def _cmp (self , other ):
1102+ def _cmp (self , other , allow_mixed = False ):
11031103 assert isinstance (other , time )
11041104 mytz = self ._tzinfo
11051105 ottz = other ._tzinfo
@@ -1118,7 +1118,10 @@ def _cmp(self, other):
11181118 (other ._hour , other ._minute , other ._second ,
11191119 other ._microsecond ))
11201120 if myoff is None or otoff is None :
1121- raise TypeError ("cannot compare naive and aware times" )
1121+ if allow_mixed :
1122+ return 2 # arbitrary non-zero value
1123+ else :
1124+ raise TypeError ("cannot compare naive and aware times" )
11221125 myhhmm = self ._hour * 60 + self ._minute - myoff // timedelta (minutes = 1 )
11231126 othhmm = other ._hour * 60 + other ._minute - otoff // timedelta (minutes = 1 )
11241127 return _cmp ((myhhmm , self ._second , self ._microsecond ),
@@ -1615,15 +1618,15 @@ def dst(self):
16151618
16161619 def __eq__ (self , other ):
16171620 if isinstance (other , datetime ):
1618- return self ._cmp (other ) == 0
1621+ return self ._cmp (other , allow_mixed = True ) == 0
16191622 elif not isinstance (other , date ):
16201623 return NotImplemented
16211624 else :
16221625 return False
16231626
16241627 def __ne__ (self , other ):
16251628 if isinstance (other , datetime ):
1626- return self ._cmp (other ) != 0
1629+ return self ._cmp (other , allow_mixed = True ) != 0
16271630 elif not isinstance (other , date ):
16281631 return NotImplemented
16291632 else :
@@ -1661,7 +1664,7 @@ def __gt__(self, other):
16611664 else :
16621665 _cmperror (self , other )
16631666
1664- def _cmp (self , other ):
1667+ def _cmp (self , other , allow_mixed = False ):
16651668 assert isinstance (other , datetime )
16661669 mytz = self ._tzinfo
16671670 ottz = other ._tzinfo
@@ -1682,7 +1685,10 @@ def _cmp(self, other):
16821685 other ._hour , other ._minute , other ._second ,
16831686 other ._microsecond ))
16841687 if myoff is None or otoff is None :
1685- raise TypeError ("cannot compare naive and aware datetimes" )
1688+ if allow_mixed :
1689+ return 2 # arbitrary non-zero value
1690+ else :
1691+ raise TypeError ("cannot compare naive and aware datetimes" )
16861692 # XXX What follows could be done more efficiently...
16871693 diff = self - other # this will take offsets into account
16881694 if diff .days < 0 :
0 commit comments