- The code "Unset = object()" is quite obscure for people not familiar with the sentinel pattern.
>>> copy.deepcopy(Unset) is Unset
True
A simple implementation would be something like
def sentinel(name):
return type(name, (), {
'__repr__': lambda self: f"<{self.__class__.__name__}>",
'__copy__': lambda self: self,
'__deepcopy__': lambda self, memo: self,
})
Likely, the implementation should be refined a bit more.
While it's not rocket science, getting sentinels correct is cumbersome for end users. Providing such a function in the standard library is only a minor maintainance burden, but a significant help for users working with sentinels.
Thanks for your consideration!
Tim