[Python-ideas] Add new `Symbol` type

Joseph Jevnik joejev at gmail.com
Thu Jul 5 16:22:07 EDT 2018

I have also wanted sentinel objects many times. These are often useful
for creating a "Not Specified" default value when explicitly passing
`None` has semantic meaning.

There are a few issues with the `sentinel = object()` code. One is
that they don't repr well so they make debugging harder. Another issue
is that they cannot be pickled or copied. You also cannot take a weak
reference to a sentinel which can break some caching code and makes
them harder to use. At work we have a small helper to create sentinels
with a name and optional doc string which is open sourced here:

On Thu, Jul 5, 2018 at 3:44 PM, Ed Kellett <e+python-ideas at kellett.im> wrote:
> Hi!
> On 2018-07-05 20:38, Flavio Curella wrote:
>> More than once I've found myself wanting to create a 'sentinel' value. The
>> most common use case is to differentiate between an argument that has not
>> been provided, and an argument provided with the value `None`.
> I generally do something like
>     _nothing = object()
>> Furthermore, without a common implementation in the std library, various
>> Python libraries had to write their own implementations, which all differs
>> in functionality and behavior.
> What functionality does such a thing actually need?
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

More information about the Python-ideas mailing list