Skip to content

Commit 90feee7

Browse files
gaogaotiantianaisk
authored andcommitted
pythongh-110196: Fix ipaddress.IPv6Address.__reduce__ (pythonGH-110198)
1 parent 72fe186 commit 90feee7

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

Lib/ipaddress.py

+3
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,9 @@ def __eq__(self, other):
19701970
return False
19711971
return self._scope_id == getattr(other, '_scope_id', None)
19721972

1973+
def __reduce__(self):
1974+
return (self.__class__, (str(self),))
1975+
19731976
@property
19741977
def scope_id(self):
19751978
"""Identifier of a particular zone of the address's scope.

Lib/test/test_ipaddress.py

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""Unittest for ipaddress module."""
55

66

7+
import copy
78
import unittest
89
import re
910
import contextlib
@@ -542,11 +543,17 @@ def assertBadPart(addr, part):
542543

543544
def test_pickle(self):
544545
self.pickle_test('2001:db8::')
546+
self.pickle_test('2001:db8::%scope')
545547

546548
def test_weakref(self):
547549
weakref.ref(self.factory('2001:db8::'))
548550
weakref.ref(self.factory('2001:db8::%scope'))
549551

552+
def test_copy(self):
553+
addr = self.factory('2001:db8::%scope')
554+
self.assertEqual(addr, copy.copy(addr))
555+
self.assertEqual(addr, copy.deepcopy(addr))
556+
550557

551558
class NetmaskTestMixin_v4(CommonTestMixin_v4):
552559
"""Input validation on interfaces and networks is very similar"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ``__reduce__`` method to :class:`IPv6Address` in order to keep ``scope_id``

0 commit comments

Comments
 (0)