Thanks for the link!

On Tue, Nov 24, 2020 at 2:15 PM Sebastian Rittau <srittau@rittau.biz> wrote:
Am 24.11.20 um 07:17 schrieb Andrew Svetlov:
> In Python there is a wide-spread idiom of using specific object
> instances as markers:
>
> MARKER = object()
>
> def f(arg) ->
>   if arg is MARKER:
>      do_something_special()
>   else:
>      process_arg_as_string(arg)
>
> When I add type hints my initial thought was decorating MARKER as
> constant literal:
>
> from typing import Final, Literal, Union
>
> MARKER: Final[object] = object()
>
> def f(arg: Union[str, Literal[MARKER]]) -> None:
>     pass
>
> MARKER is declared as a final value, it cannot be changed from the
> typing perspective and IMHO satisfies requirements for Literal.
>
> Sure, it doesn't work with the current mypy but maybe the proposal
> makes sense?

There is some prior discussion about such a feature in this issue:
https://github.com/python/typing/issues/689.

  - Sebastian
_______________________________________________
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: andrew.svetlov@gmail.com


--
Thanks,
Andrew Svetlov