Skip to content

Commit 59bf799

Browse files
gh-74876: Forbid subclassing copyreg.Proxy
The picklers only recognize exact instances of copyreg.Proxy, so instances of a subclass would be pickled as ordinary objects. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a24ccf4 commit 59bf799

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

‎Lib/copyreg.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class Proxy:
3535

3636
__slots__ = ('obj',)
3737

38+
def __init_subclass__(cls, /, **kwargs):
39+
raise TypeError("type 'Proxy' is not an acceptable base type")
40+
3841
def __init__(self, obj):
3942
self.obj = obj
4043

‎Lib/test/test_copyreg.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ def test_bool(self):
4949
import copy
5050
self.assertEqual(True, copy.copy(True))
5151

52+
def test_proxy_not_subclassable(self):
53+
with self.assertRaisesRegex(TypeError, 'not an acceptable base type'):
54+
class P(copyreg.Proxy):
55+
pass
56+
5257
def test_extension_registry(self):
5358
mod, func, code = 'junk1 ', ' junk2', 0xabcd
5459
e = ExtensionSaver(code)

0 commit comments

Comments
 (0)