![](https://secure.gravatar.com/avatar/7775d42d960a69e98fecf270bdeb6f57.jpg?s=120&d=mm&r=g)
Nov. 23, 2020
10:17 p.m.
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? -- Thanks, Andrew Svetlov