summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTian Gao <gaogaotiantian@hotmail.com>2023-10-22 18:50:51 (GMT)
committerGitHub <noreply@github.com>2023-10-22 18:50:51 (GMT)
commit767f416feb551f495bacfff1e9ba1e6672c2f24e (patch)
tree3a6e8d6afdd83ed9372c15759aa8f2617a4a7733
parentb845a9e145b2f133270aa07836c7e6a385066c00 (diff)
downloadcpython-767f416feb551f495bacfff1e9ba1e6672c2f24e.zip
cpython-767f416feb551f495bacfff1e9ba1e6672c2f24e.tar.gz
cpython-767f416feb551f495bacfff1e9ba1e6672c2f24e.tar.bz2
gh-110196: Fix ipaddress.IPv6Address.__reduce__ (GH-110198)
-rw-r--r--Lib/ipaddress.py3
-rw-r--r--Lib/test/test_ipaddress.py7
-rw-r--r--Misc/NEWS.d/next/Library/2023-10-02-05-23-27.gh-issue-110196.djwt0z.rst1
3 files changed, 11 insertions, 0 deletions
diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py
index f5aba43..68ddfbe 100644
--- a/Lib/ipaddress.py
+++ b/Lib/ipaddress.py
@@ -1970,6 +1970,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.
diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py
index 6f20494..33a0f98 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
@@ -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
index 0000000..341f338
--- /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``