From 8d0bb5b282f86c5bfd203a5bee3c834c99dc149c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 14 Dec 2024 20:34:49 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pypcode/__init__.py | 2 +- pypcode/cspec.py | 45 +++++++++++++++++++++------------------------ pypcode/ldefs.py | 12 ++++++------ pypcode/pspec.py | 34 +++++++++++++++++----------------- tests/test_cspec.py | 12 ++++++------ tests/test_pspec.py | 6 +++--- 6 files changed, 54 insertions(+), 57 deletions(-) diff --git a/pypcode/__init__.py b/pypcode/__init__.py index c8a0544..037f6e3 100644 --- a/pypcode/__init__.py +++ b/pypcode/__init__.py @@ -189,7 +189,7 @@ def __init__(self, name: str, ldefpath: str): self.ldefpath = ldefpath # Parse ldefs file into structured format - with open(ldefpath, "r") as f: + with open(ldefpath) as f: self.ldef = LanguageDefinitions.from_xml(f.read()) # Create ArchLanguage objects from structured data diff --git a/pypcode/cspec.py b/pypcode/cspec.py index 16b5e99..981a5b7 100644 --- a/pypcode/cspec.py +++ b/pypcode/cspec.py @@ -7,19 +7,19 @@ @dataclass class DataOrganization: - absolute_max_alignment: Optional[int] = None - machine_alignment: Optional[int] = None - default_alignment: Optional[int] = None - default_pointer_alignment: Optional[int] = None - wchar_size: Optional[int] = None - short_size: Optional[int] = None - integer_size: Optional[int] = None - long_size: Optional[int] = None - long_long_size: Optional[int] = None - float_size: Optional[int] = None - double_size: Optional[int] = None - long_double_size: Optional[int] = None - size_alignment_map: Dict[int, int] = field(default_factory=dict) + absolute_max_alignment: int | None = None + machine_alignment: int | None = None + default_alignment: int | None = None + default_pointer_alignment: int | None = None + wchar_size: int | None = None + short_size: int | None = None + integer_size: int | None = None + long_size: int | None = None + long_long_size: int | None = None + float_size: int | None = None + double_size: int | None = None + long_double_size: int | None = None + size_alignment_map: dict[int, int] = field(default_factory=dict) bitfield_packing_uses_ms: bool = False @classmethod @@ -27,7 +27,7 @@ def from_element(cls, element: ET.Element) -> DataOrganization: if element is None: return cls() - def get_int_attr(elem: ET.Element, attr: str) -> Optional[int]: + def get_int_attr(elem: ET.Element, attr: str) -> int | None: # Handle both attribute and element value cases if attr in elem.attrib: return int(elem.attrib[attr]) @@ -49,10 +49,7 @@ def get_int_attr(elem: ET.Element, attr: str) -> Optional[int]: uses_ms = False if packing_elem is not None: ms_conv = packing_elem.find("use_MS_convention") - uses_ms = ( - ms_conv is not None - and ms_conv.attrib.get("value", "false").lower() == "true" - ) + uses_ms = ms_conv is not None and ms_conv.attrib.get("value", "false").lower() == "true" return cls( absolute_max_alignment=get_int_attr(element, "absolute_max_alignment"), @@ -75,7 +72,7 @@ def get_int_attr(elem: ET.Element, attr: str) -> Optional[int]: @dataclass class GlobalScope: ram_present: bool = False - registers: List[str] = field(default_factory=list) + registers: list[str] = field(default_factory=list) @classmethod def from_element(cls, element: ET.Element) -> GlobalScope: @@ -92,11 +89,11 @@ def from_element(cls, element: ET.Element) -> GlobalScope: class CompilerSpec: data_organization: DataOrganization = field(default_factory=DataOrganization) global_scope: GlobalScope = field(default_factory=GlobalScope) - stackpointer_register: Optional[str] = None - returnaddress_register: Optional[str] = None - returnaddress_space: Optional[str] = None - returnaddress_offset: Optional[int] = None - returnaddress_size: Optional[int] = None + stackpointer_register: str | None = None + returnaddress_register: str | None = None + returnaddress_space: str | None = None + returnaddress_offset: int | None = None + returnaddress_size: int | None = None @classmethod def from_xml(cls, xml_string: str) -> CompilerSpec: diff --git a/pypcode/ldefs.py b/pypcode/ldefs.py index 903cd17..c4dcb03 100644 --- a/pypcode/ldefs.py +++ b/pypcode/ldefs.py @@ -36,11 +36,11 @@ class Language: slafile: str processorspec: str id: str - description: Optional[str] = None - manualindexfile: Optional[str] = None - instructionEndian: Optional[str] = None - compilers: List[Compiler] = field(default_factory=list) - external_names: List[ExternalName] = field(default_factory=list) + description: str | None = None + manualindexfile: str | None = None + instructionEndian: str | None = None + compilers: list[Compiler] = field(default_factory=list) + external_names: list[ExternalName] = field(default_factory=list) @classmethod def from_element(cls, element: ET.Element) -> Language: @@ -66,7 +66,7 @@ def from_element(cls, element: ET.Element) -> Language: @dataclass class LanguageDefinitions: - languages: List[Language] = field(default_factory=list) + languages: list[Language] = field(default_factory=list) @classmethod def from_xml(cls, xml_string: str) -> LanguageDefinitions: diff --git a/pypcode/pspec.py b/pypcode/pspec.py index 5943db7..01c871f 100644 --- a/pypcode/pspec.py +++ b/pypcode/pspec.py @@ -17,7 +17,7 @@ def from_element(cls, element: ET.Element) -> Property: @dataclass class Properties: - properties: Dict[str, str] = field(default_factory=dict) + properties: dict[str, str] = field(default_factory=dict) @classmethod def from_element(cls, element: ET.Element) -> Properties: @@ -32,8 +32,8 @@ def from_element(cls, element: ET.Element) -> Properties: @dataclass class ContextSet: space: str - values: Dict[str, int] - description: Dict[str, str] + values: dict[str, int] + description: dict[str, str] @classmethod def from_element(cls, element: ET.Element) -> ContextSet: @@ -50,7 +50,7 @@ def from_element(cls, element: ET.Element) -> ContextSet: @dataclass class TrackedSet: space: str - values: Dict[str, int] + values: dict[str, int] @classmethod def from_element(cls, element: ET.Element) -> TrackedSet: @@ -66,8 +66,8 @@ def from_element(cls, element: ET.Element) -> TrackedSet: @dataclass class ContextData: - context_set: Optional[ContextSet] = None - tracked_set: Optional[TrackedSet] = None + context_set: ContextSet | None = None + tracked_set: TrackedSet | None = None @classmethod def from_element(cls, element: ET.Element) -> ContextData: @@ -83,8 +83,8 @@ def from_element(cls, element: ET.Element) -> ContextData: @dataclass class Register: name: str - group: Optional[str] = None - vector_lane_sizes: Optional[Set[int]] = None + group: str | None = None + vector_lane_sizes: set[int] | None = None hidden: bool = False @classmethod @@ -103,7 +103,7 @@ def from_element(cls, element: ET.Element) -> Register: @dataclass class RegisterData: - registers: List[Register] = field(default_factory=list) + registers: list[Register] = field(default_factory=list) @classmethod def from_element(cls, element: ET.Element) -> RegisterData: @@ -119,7 +119,7 @@ class DefaultSymbol: name: str address: str entry: bool - type: Optional[str] = None + type: str | None = None @classmethod def from_element(cls, element: ET.Element) -> DefaultSymbol: @@ -133,7 +133,7 @@ def from_element(cls, element: ET.Element) -> DefaultSymbol: @dataclass class DefaultSymbols: - symbols: List[DefaultSymbol] = field(default_factory=list) + symbols: list[DefaultSymbol] = field(default_factory=list) @classmethod def from_element(cls, element: ET.Element) -> DefaultSymbols: @@ -146,12 +146,12 @@ def from_element(cls, element: ET.Element) -> DefaultSymbols: @dataclass class ProcessorSpec: - properties: Optional[Properties] - programcounter: Optional[str] - context_data: Optional[ContextData] - register_data: Optional[RegisterData] - default_symbols: Optional[DefaultSymbols] - incidentalcopy: Optional[List[str]] = None + properties: Properties | None + programcounter: str | None + context_data: ContextData | None + register_data: RegisterData | None + default_symbols: DefaultSymbols | None + incidentalcopy: list[str] | None = None @classmethod def from_xml(cls, xml_string: str) -> ProcessorSpec: diff --git a/tests/test_cspec.py b/tests/test_cspec.py index c77e26f..93cee76 100644 --- a/tests/test_cspec.py +++ b/tests/test_cspec.py @@ -18,7 +18,7 @@ def test_all_cspecs(self): """Test that we can parse all compiler specs without errors.""" for cspec_path in self.all_cspecs: with self.subTest(cspec_path=cspec_path): - with open(cspec_path, "r") as f: + with open(cspec_path) as f: cspec = CompilerSpec.from_xml(f.read()) # Basic validation of parsed data @@ -28,7 +28,7 @@ def test_all_cspecs(self): def test_x86_64_win_cspec(self): """Test specific x86-64 Windows compiler spec.""" cspec_path = PROCESSORS_DIR / "x86" / "data" / "languages" / "x86-64-win.cspec" - with open(cspec_path, "r") as f: + with open(cspec_path) as f: cspec = CompilerSpec.from_xml(f.read()) # Test data organization @@ -59,7 +59,7 @@ def test_x86_64_win_cspec(self): def test_x86_64_gcc_cspec(self): """Test specific x86-64 GCC compiler spec.""" cspec_path = PROCESSORS_DIR / "x86" / "data" / "languages" / "x86-64-gcc.cspec" - with open(cspec_path, "r") as f: + with open(cspec_path) as f: cspec = CompilerSpec.from_xml(f.read()) # Test data organization @@ -88,7 +88,7 @@ def test_x86_64_gcc_cspec(self): def test_aarch64_cspec(self): """Test specific AArch64 compiler spec.""" cspec_path = PROCESSORS_DIR / "AARCH64" / "data" / "languages" / "AARCH64.cspec" - with open(cspec_path, "r") as f: + with open(cspec_path) as f: cspec = CompilerSpec.from_xml(f.read()) # Test data organization @@ -113,7 +113,7 @@ def test_aarch64_cspec(self): def test_x86_32_gcc_cspec(self): """Test specific x86 32-bit GCC compiler spec.""" cspec_path = PROCESSORS_DIR / "x86" / "data" / "languages" / "x86gcc.cspec" - with open(cspec_path, "r") as f: + with open(cspec_path) as f: cspec = CompilerSpec.from_xml(f.read()) # Test data organization @@ -141,7 +141,7 @@ def test_x86_32_gcc_cspec(self): def test_arm_32_cspec(self): """Test specific ARM 32-bit compiler spec.""" cspec_path = PROCESSORS_DIR / "ARM" / "data" / "languages" / "ARM.cspec" - with open(cspec_path, "r") as f: + with open(cspec_path) as f: cspec = CompilerSpec.from_xml(f.read()) # Test data organization diff --git a/tests/test_pspec.py b/tests/test_pspec.py index d3e0642..23619b4 100644 --- a/tests/test_pspec.py +++ b/tests/test_pspec.py @@ -18,7 +18,7 @@ def test_all_pspecs(self): """Test that we can parse all processor specs without errors.""" for pspec_path in self.all_pspecs: with self.subTest(pspec_path=pspec_path): - with open(pspec_path, "r") as f: + with open(pspec_path) as f: pspec = ProcessorSpec.from_xml(f.read()) # Basic validation of parsed data @@ -64,7 +64,7 @@ def test_all_pspecs(self): def test_x86_pspec(self): """Test specific x86 processor spec.""" pspec_path = PROCESSORS_DIR / "x86" / "data" / "languages" / "x86.pspec" - with open(pspec_path, "r") as f: + with open(pspec_path) as f: pspec = ProcessorSpec.from_xml(f.read()) # Test specific x86 properties @@ -99,7 +99,7 @@ def test_x86_pspec(self): def test_arm_cortex_pspec(self): """Test specific ARM Cortex processor spec.""" pspec_path = PROCESSORS_DIR / "ARM" / "data" / "languages" / "ARMCortex.pspec" - with open(pspec_path, "r") as f: + with open(pspec_path) as f: pspec = ProcessorSpec.from_xml(f.read()) # Test ARM Cortex specific properties