On Tue, Jun 8, 2021 at 8:54 AM Sebastian Rittau <srittau@rittau.biz> wrote:
Am 08.06.21 um 17:44 schrieb Jelle Zijlstra:
Looking at your PEP, I think it would be more user-friendly if the sentinel can be used directly as a type annotation, something like this:

SENTINEL = sentinel("SENTINEL")

def print_exception(*, value=Exception | SENTINEL) -> None: ...

This would be similar to how None works, and it would make the type annotation more concise than when we use Literal.
+1
2. What should the process be, in terms of what the PEP defines and what is later implemented in mypy and similar tools?
My preference would be that the PEP specifies how this new feature interacts with typing, either by allowing sentinels as types directly (my proposal above) or by saying that PEP 586 is amended to allow sentinels in Literal.

+1

Sorry for just +1'ing, but Jelle formulated the thoughts I had. Type checkers will need to special case sentinels anyway, so using Literal[] seems to be just unnecessary noise.


Why do type checkers have to special-case sentinels? Until this idiom has become popular, using `Literal[SENTINEL]` seems the most logical approach. The only change to type checkers in that case would be to treat `sentinel` as one of the types whose values can be used in `Literal[]`.

(More generally speaking, allowing all values to be used directly instead of literals would of course be nice, but the current use of strings for forward references pretty much blocks that; I'm not sure we should start making individual exceptions for sentinels.)

--
--Guido van Rossum (python.org/~guido)