Thanks for this, Luciano!

My main issue with using class objects is that such use of them would be unusual and potentially confusing. I think that is important in general, and doubly so for something I suggest adding to the stdlib.

Additionally, I very much would like for each sentinel object to have its own dedicated class, to allow writing strict function type signatures. Once one adds that to a meta-class or class decorator, the complexity of the implementation approaches what I currently have for a sentinel() function. At that point, I can't see a clear advantage for such an approach.

- Tal

On Mon, May 24, 2021 at 7:31 PM Luciano Ramalho <> wrote:
On Mon, May 24, 2021 at 11:44 AM Tal Einat <> wrote:
> > But frankly Luciano's idea of a base class that can be subclassed seems the most startightford to me.
> Yes, and it's what I originally suggested near the beginning of this thread :)

I am sorry to have missed your previous e-mail with a base class for
sentinels, @Tal. I support that idea.

In fact, if we have a SentinelMeta metaclass, and a Sentinel base
class built from SentinelMeta, the Sentinel class can be used directly
as a sentinel without the need for subclassing—if the application does
not require a custom sentinel. If it does, then the user can subclass

The SentinelMeta could be private, to discourage misuse.

This is my implementation, after learning from @Tal's code:

Since having a Sentinel base class is desirable for ease of use, I
think it is simpler to code the __new__ method in it, instead of
coding metaclass logic to inject __new__ in the class namespace.



Luciano Ramalho
|  Author of Fluent Python (O'Reilly, 2015)
|  Technical Principal at ThoughtWorks
|  Twitter: @ramalhoorg