Blob Blame History Raw
From 03e2d16f3306e3450da0e69ae47c427d715457a9 Mon Sep 17 00:00:00 2001
From: Tomas Hrnciar <thrnciar@redhat.com>
Date: Fri, 30 Oct 2020 10:01:24 +0100
Subject: [PATCH]  Fix interpret decimal.Decimal object as an integer

Ref: https://docs.python.org/3.8/whatsnew/3.8.html

Many builtin and extension functions that take integer arguments will
now emit a deprecation warning for Decimals, Fractions and any other
objects that can be converted to integers only with a loss (e.g. that
have the `__int__()` method but do not have the `__index__()` method).
In future version they will be errors. (Contributed by Serhiy
Storchaka in bpo-36048.)

---
 src/isodate/duration.py       | 6 ++++--
 src/isodate/tests/__init__.py | 3 +++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/isodate/duration.py b/src/isodate/duration.py
index 6d1848c..96127ab 100644
--- a/src/isodate/duration.py
+++ b/src/isodate/duration.py
@@ -180,7 +180,8 @@ class Duration(object):
                 newday = maxdays
             else:
                 newday = other.day
-            newdt = other.replace(year=newyear, month=newmonth, day=newday)
+            newdt = other.replace(
+                year=int(newyear), month=int(newmonth), day=newday)
             # does a timedelta + date/datetime
             return self.tdelta + newdt
         except AttributeError:
@@ -264,7 +265,8 @@ class Duration(object):
                 newday = maxdays
             else:
                 newday = other.day
-            newdt = other.replace(year=newyear, month=newmonth, day=newday)
+            newdt = other.replace(
+                year=int(newyear), month=int(newmonth), day=newday)
             return newdt - self.tdelta
         except AttributeError:
             # other probably was not compatible with data/datetime
diff --git a/src/isodate/tests/__init__.py b/src/isodate/tests/__init__.py
index b1d46bd..7208cbd 100644
--- a/src/isodate/tests/__init__.py
+++ b/src/isodate/tests/__init__.py
@@ -29,6 +29,7 @@ Collect all test suites into one TestSuite instance.
 '''
 
 import unittest
+import warnings
 from isodate.tests import (test_date, test_time, test_datetime, test_duration,
                            test_strf, test_pickle)
 
@@ -37,6 +38,8 @@ def test_suite():
     '''
     Return a new TestSuite instance consisting of all available TestSuites.
     '''
+    warnings.filterwarnings("error", module=r"isodate(\..)*")
+
     return unittest.TestSuite([
         test_date.test_suite(),
         test_time.test_suite(),
-- 
2.26.2