Issue1950

classification
Title: datetime.date.__add__() should return NotImplemented instead of raising TypeError
Type: Severity: normal
Components: Versions: Jython 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, fwierzbicki
Priority: Keywords:

Created on 2012-07-25.00:57:36 by Arfrever, last changed 2013-02-19.18:46:14 by fwierzbicki.

Messages
msg7335 (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) Date: 2012-07-25.00:57:35
datetime.date.__add__() should return NotImplemented instead of raising TypeError, as is already mentioned in source code.
This change fixes errors in test suite of python-dateutil (http://pypi.python.org/pypi/python-dateutil).

--- Lib/datetime.py
+++ Lib/datetime.py
@@ -911,8 +911,7 @@
             self._checkOverflow(t.year)
             result = date(t.year, t.month, t.day)
             return result
-        raise TypeError
-        # XXX Should be 'return NotImplemented', but there's a bug in 2.2...
+        return NotImplemented
 
     __radd__ = __add__
msg7347 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2012-08-03.16:33:26
But, this is the behavior of CPython 2.7 (I think it is fixed in 3.3)


Python 2.7.3 (default, Apr 20 2012, 22:39:59) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import date
>>> x = date(1,2,3)
>>> y = date(4,5,6)
>>> x + y
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'datetime.date' and 'datetime.date'
msg7348 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2012-08-03.16:35:07
Marking this as deferred in hopes that we remember to fix this in 3.3.
msg7351 (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) Date: 2012-08-04.05:36:03
The suggested change in Lib/datetime.py is still correct, but apparently Jython incorrectly handles NotImplemented (issue #1955).
History
Date User Action Args
2013-02-19 18:46:14fwierzbickisetversions: + Jython 2.7, - Deferred
2012-08-04 05:36:04Arfreversetmessages: + msg7351
2012-08-03 16:35:08fwierzbickisetmessages: + msg7348
versions: + Deferred
2012-08-03 16:33:26fwierzbickisetmessages: + msg7347
2012-07-25 00:57:36Arfrevercreate