Skip to content

Commit 5868d6e

Browse files
committed
Pickle Sentinel indirectly
1 parent 50b797d commit 5868d6e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/typing_extensions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4229,10 +4229,16 @@ def __or__(self, other):
42294229
def __ror__(self, other):
42304230
return typing.Union[other, self]
42314231

4232+
@classmethod
4233+
def _unpickle_fetch_sentinel(cls, name: str, module_name: str):
4234+
"""Unpickle using the sentinels location."""
4235+
return cls(name, module_name)
4236+
42324237
def __reduce__(self):
42334238
"""Record where this sentinel is defined."""
4239+
# Avoid self.__class__ to ensure pickle data does not get locked to a subclass
42344240
return (
4235-
Sentinel, # Ensure pickle data does not get locked to a subclass
4241+
Sentinel._unpickle_fetch_sentinel,
42364242
( # Only the location of the sentinel needs to be stored
42374243
self._name,
42384244
self._module_name,

0 commit comments

Comments
 (0)