New issue 2193: datetime.timedelta chokes on seconds=future.types.newint(...) https://bitbucket.org/pypy/pypy/issues/2193/datetimetimedelta-chokes-on-seconds
posita: This came up [here](https://github.com/PythonCharmers/python-future/issues/187). There is a `future`-specific workaround (wrap values in `future`'s `native` function), but isn't very elegant. ```py Python 2.7.10 (f3ad1e1e1d6215e20d34bb65ab85ff9188c9f559, Sep 04 2015, 05:13:03) [PyPy 2.6.1 with GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>> import datetime >>>> datetime.__file__ '/.../lib/pypy/lib_pypy/datetime.pyc' >>>> from builtins import int as _int >>>> i = int(1431216000) >>>> j = long(i) >>>> k = _int(i) >>>> isinstance(i, int) True >>>> isinstance(i, long) False >>>> isinstance(j, int) False >>>> isinstance(j, long) True >>>> isinstance(k, int) False >>>> isinstance(k, long) True >>>> datetime.timedelta(seconds=i) datetime.timedelta(16565) >>>> datetime.timedelta(seconds=j) datetime.timedelta(16565) >>>> datetime.timedelta(seconds=k) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/.../lib/pypy/lib_pypy/datetime.py", line 491, in __new__ assert isinstance(s, int) AssertionError ``` The assertion comes from [these two lines](https://bitbucket.org/pypy/pypy/src/2bd0965ba1ae8cd36ccdef2f6cdf8214d0a2442a/lib_pypy/datetime.py?at=default&fileviewer=file-view-default#datetime.py-490:491): ```py s += int(seconds) # can't overflow assert isinstance(s, int) ``` Where `s` is a `newint`, `isinstance(s, int)` will be `False`. A possible workaround in `datetime.py` to accommodate `newint`s might be: ```py s += int(seconds) # can't overflow assert x <= sys.maxint and x >= (-sys.maxint - 1) ``` _______________________________________________ pypy-issue mailing list pypy-issue@python.org https://mail.python.org/mailman/listinfo/pypy-issue