From 6e921627d328b354d2ac70771c0ef3c51b4a2538 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Fri, 15 Apr 2022 22:46:01 +0100 Subject: [PATCH] compat: workaround for Literal to work in runtime in python<3.8 previously it would crash with: SyntaxError: Forward reference must be an expression -- got 'yield' (reproducible via python3 -c 'from typing import Union; Union[int, "yield"]' ) --- my/core/compat.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/my/core/compat.py b/my/core/compat.py index 8fc3ef5..a4175b6 100644 --- a/my/core/compat.py +++ b/my/core/compat.py @@ -58,9 +58,11 @@ else: if TYPE_CHECKING: from typing_extensions import Literal else: - from typing import Union # erm.. I guess as long as it's not crashing, whatever... - Literal = Union + class _Literal: + def __getitem__(self, args): + pass + Literal = _Literal() import os