Skip to content

Commit 3c3c489

Browse files
[3.11] gh-110196: Fix ipaddress.IPv6Address.__reduce__ (GH-110198) (GH-111190)
(cherry picked from commit 767f416) Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
1 parent aaa755d commit 3c3c489

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
@@ -1941,6 +1941,9 @@ def __eq__(self, other):
19411941
return False
19421942
return self._scope_id == getattr(other, '_scope_id', None)
19431943

1944+
def __reduce__(self):
1945+
return (self.__class__, (str(self),))
1946+
19441947
@property
19451948
def scope_id(self):
19461949
"""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)