Skip to content

Commit 6333253

Browse files
committed
Disable pickling
1 parent eb0e089 commit 6333253

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/test_typing_extensions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9124,6 +9124,14 @@ def test_sentinel_not_callable(self):
91249124
):
91259125
sentinel()
91269126

9127+
def test_sentinel_not_picklable(self):
9128+
sentinel = Sentinel('sentinel')
9129+
with self.assertRaisesRegex(
9130+
TypeError,
9131+
"Cannot pickle 'Sentinel' object"
9132+
):
9133+
pickle.dumps(sentinel)
9134+
91279135

91289136
if __name__ == '__main__':
91299137
main()

src/typing_extensions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4258,6 +4258,9 @@ def __or__(self, other):
42584258
def __ror__(self, other):
42594259
return Union[other, self]
42604260

4261+
def __getstate__(self):
4262+
raise TypeError(f"Cannot pickle {type(self).__name__!r} object")
4263+
42614264

42624265
# Aliases for items that are in typing in all supported versions.
42634266
# Explicitly assign these (rather than using `from typing import *` at the top),

0 commit comments

Comments
 (0)