PEP 661: Sentinel Values

I am having second thoughts about this.

This proposal offers sentinels that are different in behaviour to None and other standard Python sentinels.

None is Singleton while this proposal offers instances of the same class.

It would be nice to keep things in line to make life easier:

type(None)              # NoneType
type(None)() is None    # True

sentinel · PyPI also obeys the above. The only part that they haven’t figured out is pickle.dumps(Sentinel.__class__).
But it is doable without changes to pickle by copyreg.pickle(SentinelMeta, ...).

While this proposal does not work like this:

Something = Sentinel('Something')
type(Something)    # Sentinel

I would suggest an alternative to introduce singleton.py module which implements singleton type sentinels, such as None and PyPI.sentinel. Then later on _singletonmodule.c could be introduced and common part (Singleton class) could be moved to C leaving its specialisation in singleton.py.

This way there would be a common standard and this would align with Singletonobject.c and unification of `singletons` and `singlenels`

This would be slightly more complex than what is proposed in this PEP, however I think the cost is worth it to keep things consistent. Especially when implementation is 100-200 lines long.

1 Like