homebrew-file
homebrew-file copied to clipboard
TypeAlias at python3.8 and python3.9
Python3.8 does not allow alias with dict, list, tuple even with from __future__ import annotations
from __future__ import annotations
MyType = dict[str, str]
This shows an error like:
E TypeError: 'type' object is not subscriptable
It can be written with typing.Dict (typing.List, typing.Tuple)
from __future__ import annotations
from typing import Dict
MyType = Dict[str, str]
This is OK even at python3.8.
This should be updated when python3.8 is dropped from the support.
From python3.10, typing.TypeAlias is introduced to declare aliases.
But it can not be imported by from __future__ import annotations.
It can be used when only >=python3.10 is supported.