Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9e73c71

Browse filesBrowse files
[3.12] gh-110196: Fix ipaddress.IPv6Address.__reduce__ (GH-110198) (GH-111191)
(cherry picked from commit 767f416) Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
1 parent 06fe868 commit 9e73c71
Copy full SHA for 9e73c71

File tree

Expand file treeCollapse file tree

3 files changed

+11
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+11
-0
lines changed

‎Lib/ipaddress.py

Copy file name to clipboardExpand all lines: Lib/ipaddress.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,6 +1938,9 @@ def __eq__(self, other):
19381938
return False
19391939
return self._scope_id == getattr(other, '_scope_id', None)
19401940

1941+
def __reduce__(self):
1942+
return (self.__class__, (str(self),))
1943+
19411944
@property
19421945
def scope_id(self):
19431946
"""Identifier of a particular zone of the address's scope.

‎Lib/test/test_ipaddress.py

Copy file name to clipboardExpand all lines: Lib/test/test_ipaddress.py
+7Lines changed: 7 additions & 0 deletions
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"""
+1Lines changed: 1 addition & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.