I like the idea, quite a bit. Unfortunately, string annotations are currently reserved for type annotations (particularly for forward references), so`x: str` and `x: "str"` are currently equivalent. This would rule-out using string literals in the manner you suggest.
On Sat, 2022-02-05 at 23:21 +0400, Abdulla Al Kathiri wrote:
Hello all,
Why can’t we use the literals directly as types? For example,
x: Literal[1, 2, 3] = 3
name: Literal[“John”] | None = “John"
Become ….
x: 1 | 2 | 3 = 3
name: “John” | None = “John"
def open(file: Path | str, mode: “w” | “a” = “w”): …
Best Regards,
Abdulla
_______________________________________________