David Fraser wrote:
Hi
I have been testing out pypy for the first time...
I wanted to get the datetime module working and found that there was a pure python implementation of it done before the C implementation, in the nondist/sandbox/datetime module on Python CVS.
This implementation works fairly well on pypy:
- in order to test it, the attached patch to test_datetime is needed to avoid problems with pickle and gc
- other than pickling, the only test failures are below
The datetime.py can be got directly here:
http://cvs.sourceforge.net/viewcvs.py/*checkout*/python/python/nondist/sandbox/datetime/datetime.py?content-type=text%2Fplain&rev=1.160
======================================================================
FAIL: test_subclass_timedelta (__main__.TestTimeDelta)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_datetime.py", line 469, in test_subclass_timedelta
self.assert_(type(t3) is timedelta)
File "/share/sjsoft/code/Python/pypy/dist-pypy/lib-python-2.3.4/unittest.py", line 278, in failUnless
if not expr: raise self.failureException, msg
AssertionError
This test fails in standard Python as well ... the basic problem is the datetime.py produced a derived type T when adding two T's together, the test expects it to produce a standard datetime.timedelta objects.
I've attached a patch (as plain text) that makes the result of arithmetic operations between datetime.timedelta objects standard datetime.timedelta objects. Not sure why this is a good thing, or if it should be done to the rest of the datetime code (its not tested for) - there are a few other places where self.__class__ is used to generate a derived result
With this patch and the classmodule patch all the non-pickle tests pass on my pypy.
David
PS this should check if text/x-patch mime types are now getting through to the list too.
--- datetime.py-1.160 2005-02-03 11:03:47.000000000 +0200
+++ datetime.py 2005-02-04 10:56:29.643217391 +0200
@@ -575,7 +575,7 @@
def __add__(self, other):
if isinstance(other, timedelta):
- return self.__class__(self.__days + other.__days,
+ return timedelta(self.__days + other.__days,
self.__seconds + other.__seconds,
self.__microseconds + other.__microseconds)
return NotImplemented
@@ -593,7 +593,7 @@
return NotImplemented
def __neg__(self):
- return self.__class__(-self.__days,
+ return timedelta(-self.__days,
-self.__seconds,
-self.__microseconds)
@@ -608,7 +608,7 @@
def __mul__(self, other):
if isinstance(other, (int, long)):
- return self.__class__(self.__days * other,
+ return timedelta(self.__days * other,
self.__seconds * other,
self.__microseconds * other)
return NotImplemented
@@ -619,7 +619,7 @@
if isinstance(other, (int, long)):
usec = ((self.__days * (24*3600L) + self.__seconds) * 1000000 +
self.__microseconds)
- return self.__class__(0, 0, usec // other)
+ return timedelta(0, 0, usec // other)
return NotImplemented
__floordiv__ = __div__
_______________________________________________ [email protected] http://codespeak.net/mailman/listinfo/pypy-dev
