Here is a simple implementation of that Sentinel class:

https://github.com/fluentpython/example-code-2e/blob/master/25-class-metaprog/sentinel/sentinel.py

Tests in the same directory. That's not a real package yet, just a
couple of super simple examples I may use in Fluent Python 2e.

Cheers,

Luciano

On Sun, May 23, 2021 at 9:37 PM Luciano Ramalho <luci...@ramalho.org> wrote:
>
> Sorry about my detour into the rejected idea of a factory function.
>
> But how about this class-based API?
>
> class NotGiven(Sentinel):
>     pass
>
>
> Now I can use NotGiven as the sentinel, and its default repr is <NotGiven>.
>
> Behind the scenes we can have a SentinelMeta metaclass with all the
> magic that could be required--including the default __repr__ method.
>
> Cheers,
>
> Luciano
>
>
>
> > >
> > > (Note: This link will break once the temporary branch is deleted.)
> > >
> > > I wrote it to summarize the discussions, organize my thoughts and
> > > explore the options. I stopped working on it late at night and sent a
> > > link to a few people to get some opinions. I didn’t intend to make it
> > > public yet, but it was noticed and replied to on the
> > > discuss.python.org thread where I put up the poll [1], so the cat is
> > > out of the proverbial bag now…
> > >
> > > Luciano, your wish is granted! ;)
> > > - Tal Einat
> > >
> > > [1] https://discuss.python.org/t/sentinel-values-in-the-stdlib/8810/
> >
> >
> >
> > --
> > Luciano Ramalho
> > |  Author of Fluent Python (O'Reilly, 2015)
> > |     http://shop.oreilly.com/product/0636920032519.do
> > |  Technical Principal at ThoughtWorks
> > |  Twitter: @ramalhoorg
>
>
>
> --
> Luciano Ramalho
> |  Author of Fluent Python (O'Reilly, 2015)
> |     http://shop.oreilly.com/product/0636920032519.do
> |  Technical Principal at ThoughtWorks
> |  Twitter: @ramalhoorg



-- 
Luciano Ramalho
|  Author of Fluent Python (O'Reilly, 2015)
|     http://shop.oreilly.com/product/0636920032519.do
|  Technical Principal at ThoughtWorks
|  Twitter: @ramalhoorg
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/DAUQOKAJG7FZYY24JBG7ZIGA3TFZA4OY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to