msg123617 - (view) |
Author: Hirokazu Yamamoto (ocean-city) *  |
Date: 2010-12-08 15:37 |
I'm not sure why this happens, I can see this on official python3.2 beta1 windows binary. C:\Python32>.\python -m test.regrtest test_datetime [1/1] test_datetime test test_datetime failed -- Traceback (most recent call last): File "c:\Python32\lib\test\datetimetester.py", line 1628, in test_computations self.assertRaises(TypeError, lambda: a+i) AssertionError: TypeError not raised by 1 test failed: test_datetime |
|
|
msg123619 - (view) |
Author: Brian Curtin (brian.curtin) *  |
Date: 2010-12-08 15:41 |
I don't see this on a US/English version of Windows 7 with 3.2b1 installed. |
|
|
msg123622 - (view) |
Author: Alexander Belopolsky (belopolsky) *  |
Date: 2010-12-08 17:43 |
Hirokazu, Please rerun the test with a -v flag like this: C:\Python32>.\python -m test.regrtest -v test_datetime This should tell us whether the failure comes from C (Fast) implementation or Python (Pure) one. The test in question simply tests that date(y, m, d) + 1 and datetime(y, m, d) + 1 raise TypeError. Please see if you can reproduce the problem outside of the unit tests. |
|
|
msg123627 - (view) |
Author: Hirokazu Yamamoto (ocean-city) *  |
Date: 2010-12-08 18:15 |
====================================================================== FAIL: test_computations (test.datetimetester.TestSubclassDateTime_Fast) ---------------------------------------------------------------------- Traceback (most recent call last): File "c:\Python32\lib\test\datetimetester.py", line 1628, in test_computations self.assertRaises(TypeError, lambda: a+i) AssertionError: TypeError not raised by > Please see if you can reproduce the problem outside of the unit tests. I'll try. |
|
|
msg123636 - (view) |
Author: Hirokazu Yamamoto (ocean-city) *  |
Date: 2010-12-08 19:21 |
This is shortest code to reproduce. But strange, I can see TypeError on VC6(both Debug and Release) E:\>e:\python-dev\py3k\pc\VC6\python.exe x.py Traceback (most recent call last): File "x.py", line 10, in a+i TypeError: unsupported operand type(s) for +: 'SubclassDatetime' and 'int' ///////////////////////////////////////////// from datetime import datetime class SubclassDatetime(datetime): sub_var = 1 a = SubclassDatetime(2002, 3, 2, 17, 6) # Add/sub ints or floats should be illegal for i in 1, 1.0: a+i |
|
|
msg123638 - (view) |
Author: Hirokazu Yamamoto (ocean-city) *  |
Date: 2010-12-08 19:39 |
By changing from datetime import datetime to from _datetime import datetime I can see same behavior. |
|
|
msg123640 - (view) |
Author: Alexander Belopolsky (belopolsky) *  |
Date: 2010-12-08 19:55 |
On Wed, Dec 8, 2010 at 2:21 PM, Hirokazu Yamamoto <report@bugs.python.org> wrote: .. > ///////////////////////////////////////////// > > from datetime import datetime > > class SubclassDatetime(datetime): > sub_var = 1 > > a = SubclassDatetime(2002, 3, 2, 17, 6) > # Add/sub ints or floats should be illegal > for i in 1, 1.0: > a+i > What is the output here? If you do this at the '>>>' prompt, you should see the results, if you do it in a script, please add a print(). Does this also happen with plain datetime or only a subclass? What about time, date, or their subclasses? |
|
|
msg123642 - (view) |
Author: Hirokazu Yamamoto (ocean-city) *  |
Date: 2010-12-08 20:24 |
"NotImplementedError" was printed. This happened when subclass of date or subclass of datetime. (plain classes and subclass of time didn't print this) //////////////////////////////////// // Code from _datetime import date, datetime class SubclassDate(date): sub_var = 1 a = SubclassDate(2002, 3, 2) for i in 1, 1.0: print(a+i) # "NotImplemented" class SubclassDateTime(datetime): sub_var = 1 a = SubclassDateTime(2002, 3, 2, 3, 5) for i in 1, 1.0: print(a+i) # "NotImplemented" a-i # TypeError: unsupported operand type(s) for -: 'SubclassDateTime' and 'float' //////////////////////////////////// // Result E:\python-dev\py3k>c:\Python32\python.exe \x.py NotImplemented NotImplemented NotImplemented NotImplemented Traceback (most recent call last): File "\x.py", line 17, in a-i # TypeError TypeError: unsupported operand type(s) for -: 'SubclassDateTime' and 'float' //////////////////////////////////////// I hope this helps. |
|
|
msg123645 - (view) |
Author: Hirokazu Yamamoto (ocean-city) *  |
Date: 2010-12-08 20:25 |
Sorry, - "NotImplementedError" was printed + "NotImplemented" was printed |
|
|
msg123648 - (view) |
Author: Alexander Belopolsky (belopolsky) *  |
Date: 2010-12-08 20:39 |
> + "NotImplemented" was printed Hmm, looks like a compiler bug to me. Can anyone reproduce this on a debug build? In any case, someone with a Windows setup will have to troubleshoot this further. Note that the code in abstract.c is supposed to convert NotImplemented returns to type errors: static PyObject * binary_op(PyObject *v, PyObject *w, const int op_slot, const char *op_name) { PyObject *result = binary_op1(v, w, op_slot); if (result == Py_NotImplemented) { Py_DECREF(result); return binop_type_error(v, w, op_name); } return result; } It should be possible to find out why this is not happening by stepping through this code with a debugger. |
|
|
msg129910 - (view) |
Author: Max (max-alleged) |
Date: 2011-03-02 18:05 |
This is still occurring with the release version of Python 3.2, installed from the 32-bit MSI, on Windows XP. |
|
|
msg166449 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2012-07-26 01:09 |
I do not see the error with installed 3.2.3. I **DO** see it consistently, when running the test with installed 3.3.0b1 on 64 bit Win 7. The only failure is ====================================================================== FAIL: test_computations (test.datetimetester.TestSubclassDateTime_Fast) ---------------------------------------------------------------------- Traceback (most recent call last): File "C:\Programs\Python33\lib\test\datetimetester.py", line 1640, in test_computations self.assertRaises(TypeError, lambda: a+i) AssertionError: TypeError not raised by ionError: TypeError not raised by The other 9 runs of test_computations pass. test_computations (test.datetimetester.TestDate_Pure) ... ok test_computations (test.datetimetester.TestDateTimeTZ_Pure) ... ok test_computations (test.datetimetester.TestTimeDelta_Pure) ... ok test_computations (test.datetimetester.TestSubclassDateTime_Pure) ... ok test_computations (test.datetimetester.TestDateTime_Pure) ... ok test_computations (test.datetimetester.TestDate_Fast) ... ok test_computations (test.datetimetester.TestDateTimeTZ_Fast) ... ok test_computations (test.datetimetester.TestTimeDelta_Fast) ... ok test_computations (test.datetimetester.TestDateTime_Fast) ... ok I reproduce in same way Hirokazo does. >>> class Sub(datetime): pass >>> dsub = Sub(2002, 1, 31) >>> dsub+1 NotImplemented >>> d = datetime(2000,1,1) >>> d+1 Traceback (most recent call last): File "<pyshell#28>", line 1, in b+1 TypeError: unsupported operand type(s) for +: 'datetime.datetime' and 'int' My understanding of a+b is that a.__add__(b) is tried and if it NotImplemented, which d and dsub.__add__(1) do, b.__radd__(a) is tried. If that does the same, TypeError is raised. 1 .__radd__(x) returns NotImplemented for both d and dsub, but TypeError is raised only for d, not dsub. Alexander, there are known problems with abstract.c #11477 Nick, I nosied you because you have worked on the binary op dance. Are there special problems for Python subclasses of builtins? Is this problem the same or related to the one in #11477? |
|
|
msg166451 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2012-07-26 01:54 |
The precedence problems described in #11477 shouldn't factor into this case - that issue is specific to C level types that implement + and * via tp_as_sequence *without* implementing the corresponding slots in tp_as_number. That's not the case here, since datetime types *only* implement the slots via tp_as_number. I can't reproduce the failure at all, so here's a couple of tricks for Windows users trying to reproduce or investigate the problem: # Getting the C version of datetime: import _datetime as cdt # Getting the pure Python version of datetime: from test.support import import_fresh_module pydt = import_fresh_module("datetime", blocked=["_datetime"]) # Test the results of all the following operations d+1 1+d d.__add__(1) d.__radd__(1) 1 .__add__(d) 1 .__radd__(d) # For the following kinds of "d" d = cdt.datetime(1, 2, 3) d = pydt.datetime(1, 2, 3) class SubC(cdt.datetime): pass d = SubC(1, 2, 3) class SubPy(cdt.datetime): pass d = SubPy(1, 2, 3) |
|
|
msg166453 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2012-07-26 02:59 |
Both subclasses return NotImplemented for d+1. Otherwise, TypeError or NotImplemented as expected. See file. |
|
|
msg195473 - (view) |
Author: Ezio Melotti (ezio.melotti) *  |
Date: 2013-08-17 14:22 |
Is this still an issue? |
|
|
msg195503 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2013-08-17 18:54 |
test_datetime passes on current 3.3 and 3.4. datetimetest.py now gives the same answer for all 4 classes unsupported operand type(s) for +: 'SubPy' and 'int' unsupported operand type(s) for +: 'int' and 'SubPy' NotImplemented NotImplemented NotImplemented NotImplemented whereas the first line for the two subclasses was previously NotImplemented. I presume the above is the correct behavior, so closing. |
|
|