On 5/20/2021 3:24 PM, Ronald Oussoren via Python-Dev wrote:


On 20 May 2021, at 19:10, Luciano Ramalho <luciano@ramalho.org> wrote:

I'd like to learn about use cases where `...` (a.k.a. `Ellipsis`) is
not a good sentinel. It's a pickable singleton testable with `is`,
readily available, and extremely unlikely to appear in a data stream.
Its repr is "Ellipsis".

If you don't like the name for this purpose, you can always define a
constant (that won't fix the `repr`, obviously, but helps with source
code readability).

SENTINEL = ...

I can't think of any case where I'd rather have my own custom
sentinel, or need a special API for sentinels. Probably my fault, of
course. Please enlighten me!

One use case for a sentinel that is not a predefined (builtin) singleton is APIs where an arbitrary user specified value can be used.

One example of this is the definition of dataclasses.field:

dataclasses.field(*default=MISSINGdefault_factory=MISSINGrepr=Truehash=Noneinit=Truecompare=Truemetadata=None)

Here the “default” and “default_factory” can be an arbitrary value, and any builtin singleton could be used. Hence the use of a custom module-private sentinel that cannot clash with values used by users of the module (unless those users poke at private details of the module, but then all bets are off anyway).

That’s why I don’t particularly like the proposal of using Ellipsis as the sanctioned sentinel value. It would be weird at best that the default for a dataclass field can be any value, except for the builtin Ellipsis value.

Completely agree. I'm opposed to Ellipsis as a sentinel for this reason, at least for dataclasses. I can easily see wanting to store an Ellipsis in a field of a dataclass that's describing a function's parameters. And I can even see it being the default= value. Not so much default_factory=, but they may as well be the same.

Eric