From 7612df4aacb37033e965aaadb3964aeaf6ff6895 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Sun, 1 Oct 2023 22:19:26 -0700 Subject: [PATCH 1/4] Fix ipaddress.IPv6Address.__reduce__ --- Lib/ipaddress.py | 3 +++ Lib/test/test_ipaddress.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index f5aba434fd4253..68ddfbeb4bc212 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1970,6 +1970,9 @@ def __eq__(self, other): return False return self._scope_id == getattr(other, '_scope_id', None) + def __reduce__(self): + return (self.__class__, (str(self),)) + @property def scope_id(self): """Identifier of a particular zone of the address's scope. diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py index 6f204948c9fc48..03ecc4434bb96d 100644 --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -4,6 +4,7 @@ """Unittest for ipaddress module.""" +import copy import unittest import re import contextlib @@ -547,6 +548,11 @@ def test_weakref(self): weakref.ref(self.factory('2001:db8::')) weakref.ref(self.factory('2001:db8::%scope')) + def test_copy(self): + addr = self.factory('2001:db8::%scope') + self.assertEqual(addr, copy.copy(addr)) + self.assertEqual(addr, copy.deepcopy(addr)) + class NetmaskTestMixin_v4(CommonTestMixin_v4): """Input validation on interfaces and networks is very similar""" From 0b3fabc4bdae3e8d0b885ad0a635e074a34de748 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 05:23:29 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-10-02-05-23-27.gh-issue-110196.djwt0z.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-10-02-05-23-27.gh-issue-110196.djwt0z.rst diff --git a/Misc/NEWS.d/next/Library/2023-10-02-05-23-27.gh-issue-110196.djwt0z.rst b/Misc/NEWS.d/next/Library/2023-10-02-05-23-27.gh-issue-110196.djwt0z.rst new file mode 100644 index 00000000000000..341f3380fffd60 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-10-02-05-23-27.gh-issue-110196.djwt0z.rst @@ -0,0 +1 @@ +Add ``__reduce__`` method to :class:`IPv6Address` in order to keep ``scope_id`` From 9584c06073106459db7266c33f9d5c732e6a0cfa Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Sun, 1 Oct 2023 23:52:11 -0700 Subject: [PATCH 3/4] remove trailing spaces --- Lib/test/test_ipaddress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py index 03ecc4434bb96d..5013ea2dd4890e 100644 --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -551,7 +551,7 @@ def test_weakref(self): def test_copy(self): addr = self.factory('2001:db8::%scope') self.assertEqual(addr, copy.copy(addr)) - self.assertEqual(addr, copy.deepcopy(addr)) + self.assertEqual(addr, copy.deepcopy(addr)) class NetmaskTestMixin_v4(CommonTestMixin_v4): From 5ce6c6021ff633ae84738185d88fbf3352611954 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Sun, 1 Oct 2023 23:54:34 -0700 Subject: [PATCH 4/4] Add scope id for pickle test --- Lib/test/test_ipaddress.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py index 5013ea2dd4890e..33a0f9894a32f9 100644 --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -543,6 +543,7 @@ def assertBadPart(addr, part): def test_pickle(self): self.pickle_test('2001:db8::') + self.pickle_test('2001:db8::%scope') def test_weakref(self): weakref.ref(self.factory('2001:db8::'))