
On Sun, Sep 11, 2022 at 4:55 AM Steven D'Aprano <steve@pearwood.info> wrote:
I haven't read the PEP yet, so this should not be read as either support of or opposition to the design, just commenting on one aspect.
Given what you've written, I recommend reading it. It's relatively short and directly addresses what you've brought up here.
On Sat, Sep 10, 2022 at 01:42:38PM -0700, Christopher Barker wrote:
The current design is that sentinels with the same name from the same module will always be identical. So for example `Sentinel("name") is Sentinel("name")` will be true.
Hmm -- so it's a semi-singleton -- i.e. behaves like a singlton, but only in a particular module namespace. [...] It would be nice if they could be true singletons, but that would require a python-global registry of some sort, which is, well, impossible.
Easy peasey. Add a second, optional, parameter to the Sentinel callable (class?) to specify the namespace, defaulting to "the current module", then register the object to `builtins`.
This already exists, an optional "module_name" argument, which defaults to the current module (via frame inspection). Using the same name and module name will result in the same sentinel object.
Do you have examples of such stdlib "similar use" of sentinels? Apart from None of course.
The PEP includes a link to a list of sentinel values in the stdlib [1]. - Tal [1] https://mail.python.org/archives/list/python-dev@python.org/message/JBYXQH3N...