Open rcmdnk opened 1 year ago
Python3.8 does not allow alias with dict, list, tuple even with from __future__ import annotations
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)
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.
typing.TypeAlias
But it can not be imported by from __future__ import annotations. It can be used when only >=python3.10 is supported.
Python3.8 does not allow alias with dict, list, tuple even with
from __future__ import annotations
This shows an error like:
It can be written with
typing.Dict
(typing.List
,typing.Tuple
)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.