Jython

Issue1950

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

Created on 2012年07月25日.00:57:36 by Arfrever, last changed 2015年03月20日.18:43:03 by zyasoft.

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).
msg8497 (view) Author: Jim Baker (zyasoft) Date: 2014年05月21日.23:10:10
Is dateutil using the datetime internals in some way?
Re support in 3.x, let's not use bugs here to remind us of that sort of functionality, hopefully it's in a unit test.
msg8563 (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) Date: 2014年05月22日.10:32:01
python-dateutil defines class dateutil.relativedelta.relativedelta with __add__() method, which allows addition operation between instances of datetime.date and dateutil.relativedelta.relativedelta.
$ python2.7 -c 'import datetime, dateutil.relativedelta; print(datetime.date(2014, 5, 22) + dateutil.relativedelta.relativedelta(months=3))'
2014年08月22日
$ jython2.7 -c 'import datetime, dateutil.relativedelta; print(datetime.date(2014, 5, 22) + dateutil.relativedelta.relativedelta(months=3))'
Traceback (most recent call last):
 File "<string>", line 1, in <module>
 File "/usr/share/jython-2.7/Lib/datetime.py", line 925, in __add__
 raise TypeError
TypeError
msg9685 (view) Author: Jim Baker (zyasoft) Date: 2015年03月20日.18:42:35
Except for three exceptions re "This test fails if you don't have the dateutil timezone file installed", all dateutil tests now pass against https://github.com/dateutil/dateutil/
Duplicate of #2010. #1995 is not relevant since this update of datetime uses new style classes
Fixed by https://hg.python.org/jython/rev/daa6bf9a14d5 
msg9686 (view) Author: Jim Baker (zyasoft) Date: 2015年03月20日.18:43:03
Or rather, *no longer* relevant
History
Date User Action Args
2015年03月20日 18:43:03zyasoftsetmessages: + msg9686
2015年03月20日 18:42:35zyasoftsetstatus: open -> closed
resolution: fixed
messages: + msg9685
2014年05月22日 10:32:02Arfreversetmessages: + msg8563
2014年05月21日 23:10:10zyasoftsetnosy: + zyasoft
messages: + msg8497
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

Supported by Python Software Foundation,
Powered by Roundup

AltStyle によって変換されたページ (->オリジナル) /