[3.12] gh-110196: Fix ipaddress.IPv6Address.__reduce__ (GH-110198) (GH-111191)

(cherry picked from commit 767f416feb)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
This commit is contained in:
Miss Islington (bot) 2023-10-22 21:14:50 +02:00 committed by GitHub
parent 06fe8685a1
commit 9e73c71aa9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 0 deletions

View 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.

View 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"""

View file

@ -0,0 +1 @@
Add ``__reduce__`` method to :class:`IPv6Address` in order to keep ``scope_id``