Fix builtin and extension functions that takes integer arguments

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

Many builtin and extension functions that take integer arguments throws
error 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).
epel9
Tomas Hrnciar 4 years ago
parent 5d575e4294
commit fc57cd472b

@ -0,0 +1,67 @@
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

@ -7,6 +7,10 @@ Summary: An ISO 8601 date/time/duration parser and formatter
License: BSD License: BSD
URL: https://pypi.org/project/isodate/ URL: https://pypi.org/project/isodate/
Source0: %pypi_source Source0: %pypi_source
# Python3.10 cannot interpret decimal.Decimal object as an integer.
# This patch fixes it until PR is not merged in upstream.
# https://github.com/gweis/isodate/issues/58
Patch1: 0001-Fix-interpret-decimal-object-as-an-integer.patch
BuildArch: noarch BuildArch: noarch
BuildRequires: python3-devel BuildRequires: python3-devel
@ -45,7 +49,7 @@ Summary: %summary
%prep %prep
%autosetup -n %{srcname}-%{version} %autosetup -n %{srcname}-%{version} -p1
%build %build

Loading…
Cancel
Save