gweis / isodate

ISO 8601 date/time parser
BSD 3-Clause "New" or "Revised" License
155 stars 59 forks source link

Fix for Python 3.10 (released 2021-10-04) #68

Closed hugovk closed 2 years ago

hugovk commented 3 years ago

Fixes https://github.com/gweis/isodate/issues/58. Fixes https://github.com/gweis/isodate/issues/67.

Python 3.10 is due out on 2021-10-04, three weeks from now.

https://discuss.python.org/t/python-3-10-0rc2-is-now-available/10496?u=hugovk

This deprecation warning was added in Python 3.8:

DeprecationWarning: an integer is required (got type decimal.Decimal). Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.

For example:

Python 3.8.6 (v3.8.6:db455296be, Sep 23 2020, 13:31:39)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime as dt
>>> from isodate import Duration
>>> dt.date(2000, 3, 30) + Duration(days=1)
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/isodate/duration.py:183: DeprecationWarning: an integer is required (got type decimal.Decimal).  Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.
  newdt = other.replace(year=newyear, month=newmonth, day=newday)
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/isodate/duration.py:183: DeprecationWarning: an integer is required (got type decimal.Decimal).  Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.
  newdt = other.replace(year=newyear, month=newmonth, day=newday)
datetime.date(2000, 3, 31)
>>>

https://bugs.python.org/issue36048

In Python 3.10 it is now an error:

TypeError: 'decimal.Decimal' object cannot be interpreted as an integer

For example:

Python 3.10.0rc2+ (heads/3.10:a272ffe, Sep  8 2021, 11:20:24) [Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime as dt
>>> from isodate import Duration
>>> dt.date(2000, 3, 30) + Duration(days=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/hugo/.pyenv/versions/3.10-dev/lib/python3.10/site-packages/isodate/duration.py", line 183, in __add__
    newdt = other.replace(year=newyear, month=newmonth, day=newday)
TypeError: 'decimal.Decimal' object cannot be interpreted as an integer
>>>

https://bugs.python.org/issue37999

Failing build without fix:

Passing build with fix:

isodate is downloaded from PyPI 33 million times a month, the 52nd most popular package (https://hugovk.github.io/top-pypi-packages/), therefore I recommend making a release before 2021-10-04.


This PR also switches from Travis CI to GitHub Actions and Coveralls to Codecov, taken from https://github.com/gweis/isodate/pull/66, because testing on Travis CI is more difficult now. It only adds testing for supported Python versions. Let me know if this commit should be dropped, but I'd recommend merging #66 as well.

hugovk commented 3 years ago

This has some overlap with PR https://github.com/gweis/isodate/pull/60.

hugovk commented 3 years ago

I've put up a temporary fork with this Python 3.10 fix as isodate2 0.7.0 at https://pypi.org/project/isodate2/

danilaeremin commented 3 years ago

Merge?

hugovk commented 3 years ago

Fixed in the fork at https://github.com/isodate/isodate/pull/1.

nicholascar commented 2 years ago

The maintainer has indicated, separately to GitHub, that this is likely to be merged soon!