Skip to content

Commit

Permalink
[3.12] gh-110196: Fix ipaddress.IPv6Address.__reduce__ (GH-110198) (G…
Browse files Browse the repository at this point in the history
…H-111191)

(cherry picked from commit 767f416)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
  • Loading branch information
miss-islington and gaogaotiantian committed Oct 22, 2023
1 parent 06fe868 commit 9e73c71
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Lib/ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -1938,6 +1938,9 @@ def __eq__(self, other):
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.
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""Unittest for ipaddress module."""


import copy
import unittest
import re
import contextlib
Expand Down Expand Up @@ -542,11 +543,17 @@ def assertBadPart(addr, part):

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"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``__reduce__`` method to :class:`IPv6Address` in order to keep ``scope_id``

0 comments on commit 9e73c71

Please sign in to comment.