]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-110196: Fix ipaddress.IPv6Address.__reduce__ (GH-110198) (GH-111191)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 22 Oct 2023 19:14:50 +0000 (21:14 +0200)
committerGitHub <noreply@github.com>
Sun, 22 Oct 2023 19:14:50 +0000 (19:14 +0000)
(cherry picked from commit 767f416feb551f495bacfff1e9ba1e6672c2f24e)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Lib/ipaddress.py
Lib/test/test_ipaddress.py
Misc/NEWS.d/next/Library/2023-10-02-05-23-27.gh-issue-110196.djwt0z.rst [new file with mode: 0644]

index af1d5c4800cce8ae9e5050ccc22109586f6f0221..9ca90fd0f75ba9e3bb38cc0167e9dc971221241a 100644 (file)
@@ -1938,6 +1938,9 @@ class IPv6Address(_BaseV6, _BaseAddress):
             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.
index a5388b2e5debd815581d98605f4079fb47b912e0..fc27628af17f8dcda51e26c07d81a0c0529b9b0a 100644 (file)
@@ -4,6 +4,7 @@
 """Unittest for ipaddress module."""
 
 
+import copy
 import unittest
 import re
 import contextlib
@@ -542,11 +543,17 @@ class AddressTestCase_v6(BaseTestCase, CommonTestMixin_v6):
 
     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::'))
         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"""
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 (file)
index 0000000..341f338
--- /dev/null
@@ -0,0 +1 @@
+Add ``__reduce__`` method to :class:`IPv6Address` in order to keep ``scope_id``