From 82622adf6f31fb0aedd3602d8a60f24154d6b22e Mon Sep 17 00:00:00 2001 From: grdddj Date: Fri, 27 May 2022 16:18:08 +0200 Subject: [PATCH] fix(tools): modify type-hints to be compatible with older python versions --- common/tools/coin_info.py | 23 +++++++++++++++-------- tools/generate_ci_docs.py | 2 ++ tools/pyright_tool.py | 18 ++++++++++++------ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/common/tools/coin_info.py b/common/tools/coin_info.py index a4473980d..0d7a6c98f 100755 --- a/common/tools/coin_info.py +++ b/common/tools/coin_info.py @@ -7,7 +7,14 @@ import os import re from collections import OrderedDict, defaultdict from pathlib import Path -from typing import Any, Callable, Iterable, Iterator, Literal, TypedDict, cast +from typing import Dict # for python38 support, must be used in type aliases +from typing import List # for python38 support, must be used in type aliases +from typing import Any, Callable, Iterable, Iterator, cast + +from typing_extensions import ( # for python37 support, is not present in typing there + Literal, + TypedDict, +) try: import requests @@ -48,10 +55,10 @@ class SupportInfoItem(TypedDict): trezor2: Literal[False] | str -SupportInfo = dict[str, SupportInfoItem] +SupportInfo = Dict[str, SupportInfoItem] -WalletItems = dict[str, str] -WalletInfo = dict[str, WalletItems] +WalletItems = Dict[str, str] +WalletInfo = Dict[str, WalletItems] class Coin(TypedDict): @@ -126,8 +133,8 @@ class Coin(TypedDict): bitcore: list[str] -Coins = list[Coin] -CoinBuckets = dict[str, Coins] +Coins = List[Coin] +CoinBuckets = Dict[str, Coins] class FidoApp(TypedDict): @@ -142,7 +149,7 @@ class FidoApp(TypedDict): icon: str -FidoApps = list[FidoApp] +FidoApps = List[FidoApp] def load_json(*path: str | Path) -> Any: @@ -158,7 +165,7 @@ def load_json(*path: str | Path) -> Any: # ====== CoinsInfo ====== -class CoinsInfo(dict[str, Coins]): +class CoinsInfo(Dict[str, Coins]): """Collection of information about all known kinds of coins. It contains the following lists: diff --git a/tools/generate_ci_docs.py b/tools/generate_ci_docs.py index 63f46f918..91ddc35dd 100755 --- a/tools/generate_ci_docs.py +++ b/tools/generate_ci_docs.py @@ -16,6 +16,8 @@ Running the script: - `python generate_ci_docs.py --check` to check if documentation is up-to-date """ +from __future__ import annotations + import argparse import filecmp import os diff --git a/tools/pyright_tool.py b/tools/pyright_tool.py index c874bd4c3..8af0beac0 100755 --- a/tools/pyright_tool.py +++ b/tools/pyright_tool.py @@ -46,18 +46,24 @@ import sys import tempfile from dataclasses import dataclass from pathlib import Path -from typing import TYPE_CHECKING, Any, Final, Iterator, TypedDict +from typing import Dict # for python38 support, must be used in type aliases +from typing import List # for python38 support, must be used in type aliases +from typing import TYPE_CHECKING, Any, Iterator +from typing_extensions import ( # for python37 support, is not present in typing there + Final, + TypedDict, +) import click if TYPE_CHECKING: - LineIgnores = list["LineIgnore"] + LineIgnores = List["LineIgnore"] - FileIgnores = dict[str, LineIgnores] - FileSpecificIgnores = dict[str, list["FileSpecificIgnore"]] + FileIgnores = Dict[str, LineIgnores] + FileSpecificIgnores = Dict[str, List["FileSpecificIgnore"]] - PyrightOffIgnores = list["PyrightOffIgnore"] - FilePyrightOffIgnores = dict[str, PyrightOffIgnores] + PyrightOffIgnores = List["PyrightOffIgnore"] + FilePyrightOffIgnores = Dict[str, PyrightOffIgnores] class RangeDetail(TypedDict):