Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-110196: Fix ipaddress.IPv6Address.__reduce__ #110198

Merged
merged 4 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,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``
Loading