Brett, is there a reason you don't want to use `None` as a sentinel? It's the one singleton object whose "singleton-ness" is enforced by the runtime. Plus, all type checkers already have intimate knowledge of it, so `is not None` works for type narrowing.
Here's another idea to consider. Would it make sense to expose a new metaclass from stdlib (let's call it `SingletonMeta`) that enforces the singleton-ness of a class? Any class based on this metaclass could be instantiated only once, and an attempt to instantiate it a second time would result in a runtime exception. Type checkers could then assume that all instances of that class are the same object, and the `is X` and `is not X` type narrowing logic could take advantage of that knowledge.
-Eric
--
Eric Traut
Contributor to pyright & pylance
Microsoft Corp.
_______________________________________________
Typing-sig mailing list -- typing-sig@python.org
To unsubscribe send an email to typing-sig-leave@python.org
https://mail.python.org/mailman3/lists/typing-sig.python.org/
Member address: guido@python.org