python 3.9 compat: introduce typehelpers.py for NoneType, UnionType, TypeAlias

This commit is contained in:
InsanePrawn 2023-04-16 20:48:48 +00:00
parent c357b0a968
commit b84d2202db
9 changed files with 34 additions and 27 deletions

18
typehelpers.py Normal file
View file

@ -0,0 +1,18 @@
from typing import Union
try:
from typing import TypeAlias # type: ignore[attr-defined]
except ImportError:
from typing_extensions import TypeAlias
TypeAlias = TypeAlias
try:
from types import UnionType
except ImportError:
UnionType: TypeAlias = Union # type: ignore[no-redef]
try:
from types import NoneType
except ImportError:
NoneType: TypeAlias = type(None) # type: ignore[no-redef]