1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-13 12:59:59 +00:00

More type annotations fixes for old Python versions

This commit is contained in:
cadmic 2024-01-24 14:26:53 -08:00
parent 5f3097e65c
commit 95745454e9
2 changed files with 11 additions and 10 deletions

View file

@ -12,15 +12,16 @@ from pathlib import Path
import re import re
import subprocess import subprocess
import sys import sys
from typing import List, Optional, Tuple
@dataclass @dataclass
class Inst: class Inst:
func_name: str func_name: str
mnemonic: str mnemonic: str
regs: list[str] regs: List[str]
imm: int|None imm: Optional[int]
reloc_type: str|None reloc_type: Optional[str]
reloc_symbol: str|None reloc_symbol: Optional[str]
FUNC_RE = re.compile(r"([0-9a-f]+) <(.*)>:") FUNC_RE = re.compile(r"([0-9a-f]+) <(.*)>:")
@ -59,7 +60,7 @@ def parse_inst(func_name: str, line: str) -> Inst:
regs.append(part) regs.append(part)
return Inst(func_name, mnemonic, regs, imm, None, None) return Inst(func_name, mnemonic, regs, imm, None, None)
def run_objdump(path: Path) -> list[Inst]: def run_objdump(path: Path) -> List[Inst]:
if not path.exists(): if not path.exists():
raise Exception(f"file {path} does not exist") raise Exception(f"file {path} does not exist")
@ -113,7 +114,7 @@ def run_objdump(path: Path) -> list[Inst]:
result.pop() result.pop()
return result return result
def pair_instructions(insts1: list[Inst], insts2: list[Inst]) -> Iterator[tuple[Inst|None, Inst|None]]: def pair_instructions(insts1: List[Inst], insts2: List[Inst]) -> Iterator[Tuple[Inst|None, Inst|None]]:
differ = difflib.SequenceMatcher( differ = difflib.SequenceMatcher(
a=[(inst.func_name, inst.mnemonic) for inst in insts1], a=[(inst.func_name, inst.mnemonic) for inst in insts1],
b=[(inst.func_name, inst.mnemonic) for inst in insts2], b=[(inst.func_name, inst.mnemonic) for inst in insts2],

View file

@ -1,7 +1,7 @@
import csv import csv
from dataclasses import dataclass from dataclasses import dataclass
from pathlib import Path from pathlib import Path
import typing from typing import List, Optional
@dataclass @dataclass
class DmaFile: class DmaFile:
@ -10,10 +10,10 @@ class DmaFile:
vrom_end: int vrom_end: int
rom_start: int rom_start: int
rom_end: int rom_end: int
overlay_vram_start: typing.Optional[int] overlay_vram_start: Optional[int]
overlay_dir: typing.Optional[str] overlay_dir: Optional[str]
def parse_file_addresses(path: Path) -> typing.List[DmaFile]: def parse_file_addresses(path: Path) -> List[DmaFile]:
result = [] result = []
with open(path) as f: with open(path) as f:
reader = csv.DictReader(f) reader = csv.DictReader(f)