mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-17 20:08:12 +00:00
fix(tools): fix invalid (in python 3.8 and lower) type aliases
This commit is contained in:
parent
4e2129e0a0
commit
5c803ab19d
@ -47,7 +47,16 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Final, TypedDict
|
from typing import Any, Final, TypedDict, TYPE_CHECKING
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
LineIgnores = list[LineIgnore]
|
||||||
|
|
||||||
|
FileIgnores = dict[str, LineIgnores]
|
||||||
|
FileSpecificIgnores = dict[str, list[FileSpecificIgnore]]
|
||||||
|
|
||||||
|
PyrightOffIgnores = list[PyrightOffIgnore]
|
||||||
|
FilePyrightOffIgnores = dict[str, PyrightOffIgnores]
|
||||||
|
|
||||||
|
|
||||||
class RangeDetail(TypedDict):
|
class RangeDetail(TypedDict):
|
||||||
@ -68,9 +77,6 @@ class Error(TypedDict):
|
|||||||
rule: str
|
rule: str
|
||||||
|
|
||||||
|
|
||||||
Errors = list[Error]
|
|
||||||
|
|
||||||
|
|
||||||
class Summary(TypedDict):
|
class Summary(TypedDict):
|
||||||
filesAnalyzed: int
|
filesAnalyzed: int
|
||||||
errorCount: int
|
errorCount: int
|
||||||
@ -82,7 +88,7 @@ class Summary(TypedDict):
|
|||||||
class PyrightResults(TypedDict):
|
class PyrightResults(TypedDict):
|
||||||
version: str
|
version: str
|
||||||
time: str
|
time: str
|
||||||
generalDiagnostics: Errors
|
generalDiagnostics: list[Error]
|
||||||
summary: Summary
|
summary: Summary
|
||||||
|
|
||||||
|
|
||||||
@ -98,10 +104,6 @@ class LineIgnore:
|
|||||||
ignore_statements: list[IgnoreStatement]
|
ignore_statements: list[IgnoreStatement]
|
||||||
|
|
||||||
|
|
||||||
LineIgnores = list[LineIgnore]
|
|
||||||
FileIgnores = dict[str, LineIgnores]
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class FileSpecificIgnore:
|
class FileSpecificIgnore:
|
||||||
rule: str = ""
|
rule: str = ""
|
||||||
@ -113,9 +115,6 @@ class FileSpecificIgnore:
|
|||||||
raise ValueError("Only one of rule|substring should be set")
|
raise ValueError("Only one of rule|substring should be set")
|
||||||
|
|
||||||
|
|
||||||
FileSpecificIgnores = dict[str, list[FileSpecificIgnore]]
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class PyrightOffIgnore:
|
class PyrightOffIgnore:
|
||||||
start_line: int
|
start_line: int
|
||||||
@ -123,9 +122,6 @@ class PyrightOffIgnore:
|
|||||||
already_used: bool = False
|
already_used: bool = False
|
||||||
|
|
||||||
|
|
||||||
PyrightOffIgnores = list[PyrightOffIgnore]
|
|
||||||
FilePyrightOffIgnores = dict[str, PyrightOffIgnores]
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--dev", action="store_true", help="Creating the error file and not deleting it"
|
"--dev", action="store_true", help="Creating the error file and not deleting it"
|
||||||
@ -198,7 +194,7 @@ class PyrightTool:
|
|||||||
all_files_to_check: set[str]
|
all_files_to_check: set[str]
|
||||||
all_pyright_ignores: FileIgnores
|
all_pyright_ignores: FileIgnores
|
||||||
pyright_off_ignores: FilePyrightOffIgnores
|
pyright_off_ignores: FilePyrightOffIgnores
|
||||||
real_errors: Errors
|
real_errors: list[Error]
|
||||||
unused_ignores: list[str]
|
unused_ignores: list[str]
|
||||||
inconsistencies: list[str] = []
|
inconsistencies: list[str] = []
|
||||||
|
|
||||||
@ -369,7 +365,7 @@ class PyrightTool:
|
|||||||
|
|
||||||
return pyright_results
|
return pyright_results
|
||||||
|
|
||||||
def get_all_real_errors(self) -> Errors:
|
def get_all_real_errors(self) -> list[Error]:
|
||||||
"""Analyze all pyright errors and discard all that should be ignored.
|
"""Analyze all pyright errors and discard all that should be ignored.
|
||||||
|
|
||||||
Ignores can be different:
|
Ignores can be different:
|
||||||
@ -377,7 +373,7 @@ class PyrightTool:
|
|||||||
- as per "file_specific_ignores"
|
- as per "file_specific_ignores"
|
||||||
- as per "# pyright: off" mark
|
- as per "# pyright: off" mark
|
||||||
"""
|
"""
|
||||||
real_errors: Errors = []
|
real_errors: list[Error] = []
|
||||||
for error in self.original_pyright_results["generalDiagnostics"]:
|
for error in self.original_pyright_results["generalDiagnostics"]:
|
||||||
# Special handling of cycle import issues, which have different format
|
# Special handling of cycle import issues, which have different format
|
||||||
if "range" not in error:
|
if "range" not in error:
|
||||||
|
Loading…
Reference in New Issue
Block a user